Skip to content

Instantly share code, notes, and snippets.

@ahmed4end
Created February 10, 2020 05:24
Show Gist options
  • Save ahmed4end/22b0d839fce6dc777f950f3f6ea58a23 to your computer and use it in GitHub Desktop.
Save ahmed4end/22b0d839fce6dc777f950f3f6ea58a23 to your computer and use it in GitHub Desktop.
text = "hello"
key = "key"
if len(key)<len(text):key=key*(len(text)//len(key)+1) #fix key length if shorter than text.
res = []
for i,j in enumerate(text):
res.append(chr(ord(j)^ord(key[i])))
text = "".join(res)
print("encode: ", text)
res = []
for i,j in enumerate(text):
res.append(chr(ord(j)^ord(key[i])))
print("decode: ", "".join(res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment