Skip to content

Instantly share code, notes, and snippets.

@cameronp98
Last active December 23, 2015 02:19
Show Gist options
  • Save cameronp98/2420ef47597fb023883b to your computer and use it in GitHub Desktop.
Save cameronp98/2420ef47597fb023883b to your computer and use it in GitHub Desktop.
from random import choice
# s:string, k:key, c:shift characters
e = lambda s,k,c:"".join([c[(c.index(i[1])+ord(k[i[0]]))%len(c)]for i in enumerate(s)])
d = lambda s,k,c:"".join([c[(c.index(i[1])-ord(k[i[0]]))%len(c)]for i in enumerate(s)])
s = "qwertyiop"
#c = list(map(chr,range(65,123))) # [A-Za-z] (chars for shifting)
c = list(map(chr,range(min(map(ord,s)),max(map(ord,s))+1))) # min-max char ord
#k = s[::-1] # reverse the string
k = "".join([choice(c)for i in s])
es = e(s, k, c)
ds = d(es,k, c)
print("wheel: %s" % "".join(c))
print("%s + %s -> %s" % (s,k,es))
print("%s - %s -> %s" % (es,k,ds))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment