Skip to content

Instantly share code, notes, and snippets.

@dhruvramani
Last active August 29, 2015 14:24
Show Gist options
  • Save dhruvramani/24735efb31c7e768abe4 to your computer and use it in GitHub Desktop.
Save dhruvramani/24735efb31c7e768abe4 to your computer and use it in GitHub Desktop.
Cryptic Kicker
#Messed up code ahead!
def replace_all(text, dic):
return ''.join(dic.get(ch, ch) for ch in text)
def printStars(string):
for i in string:
if not(i == " "):
print("*" ,end="")
else:
print(" ",end="")
def crypto(str1,arr):
xs=list(reversed(sorted(list(set(str1.split(" "))),key=len)))
dicti=dict()
count=1
while(not(len(xs) == 0)):
if count == 1:
if not(len(xs) == 1):
if len(xs[0]) == len(xs[1]):
printStars(str1)
return None
else:
for i in arr:
if len(i) == len(xs[0]):
for j in range(0,len(i)-1):
if not(xs[0][j] in dicti.keys()):
dicti[xs[0][j]]=i[j]
arr.remove(i)
xs.remove(xs[0])
count+=1
if len(dicti) == 1 or len(dicti) == 0:
printStars(str1)
return None
else:
printStars(str1)
return None
else:
matched=0
for i in arr:
if len(xs[0]) == len(i):
matched=1
if matched == 0:
printStars(str1)
return None
stri=replace_all(xs[0],dicti)
arra=list()
for i in (0,len(xs[0])-1):
if not(xs[0][i] == stri[i]):
arra.append(i)
for i in dicti.keys():
if dicti[i] == i:
if i in stri:
arra.append(stri.index(i))
foo2=0
for i in range(0,len(arr)):
if len(arr[i]) == len(xs[0]):
counti=0
for j in arra:
if arr[i][j] == stri[j]:
counti+=1
if counti == len(arra) and not(len(arra) == 0):
for j in range(0,len(arr[i])):
if not(xs[0][j] in dicti.keys()):
dicti[xs[0][j]]=arr[i][j]
count +=1
foo2=1
arr.remove(arr[i])
xs.remove(xs[0])
break
if foo2 == 0:
striaw=xs[0]
xs.remove(xs[0])
xs.append(striaw)
for i in str1:
print(replace_all(i,dicti),end="")
words=['and', 'dick', 'jane', 'puff', 'spot', 'yertle']
DecrytedString="bjvg xsb hxsn xsb qymm xsb rqat xsb pnetfn"
crypto(DecrytedString,words)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment