Getting 'invalid syntax' from PEP-8 for no apparent reason
I am trying to create an XOR cipher algorithm in Python but my code all of
the sudden won't run for no reason apparent to me. Error is being accused
in line 28 on the else statement.
Thanks in advance.
CODE:
on pastebin
#!/bin/env python
import sys
from os import urandom as ur
import random as rn
import string as st
if __name__ == "__main__":
plain = sys.argv[1]
strlib = list(st.letters + st.digits + st.punctuation).remove("%")
if len(sys.argv) == 2:
key = "".join([strlib[ur(1) % len(strlib)-1] for x in range(plain)])
elif len(sys.argv) == 3:
key = sys.argv[2]
else:
print "FAILED TEST (ARGUMENT QUANTITY ASSERTION)"
out = None
if len(sys.argv) < 2:
out = "insufficient"
elif len(sys.argv) > 3:
out = "excessive"
sys.exit("%s number of arguments." % out.capitalize())
if len(plain) != len(key):
print "FAILED TEST (KEY LENGTH ASSERTION)"
if len(plain) > len(key):
sys.exit("Key is %d characters shorter than cipher." %
len(plain)-len(key)
else: # This line is where the error is acused
print "Key is %d characters longer than cipher." %
len(key)-len(plain)
print "Attempting to fix by stripping out excessive
characters. Please Wait..."
key = key[:len(plain)-len(key)]
if len(plain) == len(key):
print "Successful."
else:
sys.exit("Failed. Aborting Execution.")
cipher = "".join([chr(ord(plain[x]) ^ ord(key[x])) for x in
range(plain)])
# ...
print cipher
sys.exit(0)
No comments:
Post a Comment