Links

Search This Blog

February 06, 2019

Crack The Code - Function

def X_Code(textline, n = 2, BW = 1, character = " "):
  textline = textline.upper()
  if len(textline) % 2:
    textline += "X"
  textline = [(textline[i:i+n])[::BW] for i in range(0,len(textline),n)]
  textline = character.join(textline)
  return textline


def NumberCruncherCode(textline):
  textline = textline.upper()
  nums = []
  for i in textline:
    nums.append(str(ord(i)-64))
  return "-".join(nums)


Credits:
Book: Crack the Code
Site: https://stackoverflow.com/questions/9475241/split-string-every-nth-character

No comments:

Post a Comment