The 160-bit (20-byte) key that you will use is available in the file xorkey.txt
ID: 3882598 • Letter: T
Question
The 160-bit (20-byte) key that you will use is available in the file xorkey.txt Python program runs without errors and provides encryption and decryption functions Code has comments that explain main steps of the implementation Screenshots show tests with encryption and decryption XOR is exclusive-or operation: "^" in C or theta in mathematical notation. It's a standard operation on bits: 0 0 = 0 0 1 = 1 1 0 = 1 1 1 = 0 Also note that: a a = 0 a b b = a The simple-XOR algorithm is really an embarrassment: it's nothing more than a Vigenere polyalphabetic cipher. It's here only because of its prevalence in commercial software packages, at least those in the MS-DOS and Macintosh worlds [1502, 1387]. Unfortunately, if a software security program proclaims that it has a "proprietary" encryption algorithm-significantly faster than DES-the odds are that it is some variant of this. This is symmetric algorithm. The plaintext is being XORed with a keyword to generate the ciphertext. Since XORing the same value twice restores the original, encryption and decryption use exactly the same program: P K = C C K = P There's no real security. This kind of encryption is trivial to break, even without computers [587, 1475]. It will only take a few seconds with a computer. Despite this, the list of software vendors that tout this toy algorithm as being "almost as secure as DES" is staggering [1387]. It is the algorithm (with a 160-bit repeated "key") that the NSA finally allowed the U.S. digital cellular phone industry to use for voice privacy. An XOR might keep your kid sister from reading your files, but it won't stop a cryptanalyst for more than a few minutes.Explanation / Answer
# code to encrypt a message given a key using simple xor
def encrypt(text, key):
return text^key
# code to decrypt a message given key used for encryption using simple xor
def decrypt(text, key):
return text^key
key = 0
with open("xorkey.txt") as fh:
key = fh.read()
text = input("Enter a bit string to encrypt: ")
cipher = encrypt(text, key)
decipher = decrypt(text, key)
print "Cipher text: " + cipher
print "Text after decrypting: " + decipher
# Code link in case indentation mess up: https://paste.ee/p/LVPZn
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.