Created
August 18, 2015 20:31
-
-
Save divegeek/7e4e3fe9853ab3a6fee3 to your computer and use it in GitHub Desktop.
Trivial one-time pad implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
if __name__ == "__main__": | |
if len(sys.argv) != 3: | |
print "Usage: otp.py <plaintext> <pad>" | |
exit(1) | |
plaintext = sys.argv[1].upper() | |
pad = sys.argv[2].upper() | |
if len(plaintext) != len(pad): | |
print "Pad and plaintext must be the same length" | |
exit(2) | |
if not plaintext.isalpha() or not pad.isalpha(): | |
print "Pad and plaintext must be alphabetic" | |
exit(3) | |
ciphertext = '' | |
for i in range(0, len(plaintext)): | |
ciphertext += chr((ord(plaintext[i]) + ord(pad[i])) % 26 + ord('A')) | |
print ciphertext |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment