Question: Your first assignment is implementing autokey ( one time pad ) functionality to Vernam Cipher. Initial code is attached. You can use that code to

Your first assignment is implementing autokey (one time pad) functionality to Vernam Cipher.
Initial code is attached. You can use that code to implement.
You can use any programming language, but in this case you need to implement Vernam Cipher by yourself.(i would like to use pyhton)
The assignment is as below;
- You need to have ten passwords and ten plain texts
- each plain text will be ecrypted with a different password. After encryption, the cipher text will be decrypted by the same password
- After encryption or decryption, throw away used password
- make sure, in the code, by testing that, you decrypted text and plain text are the same
- generate the password with diffie helman
- do the encrption and decrytion on two different servers, witout sharing the password (diffie hellman)
Complete all the required tasks in the assignment using this code below
# Vernam Cipher
import random
#and
"""
AND
A B R
000
010
100
111
OR
A B R
000
011
101
111
XOR
A B R
000
011
101
110
"""
def generate_key(plaintext_length):
key =''.join(random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ') for _ in range(plaintext_length))
return key
def encrypt(plaintext, key):
#a =>97
# HELLO
# ASDF
# zip => HELLO ASDF
# c1 c2
# H A
# E S
# 7201001000
# 7101000111
# XOR:
# 00001111
ciphertext =""
for p, k in zip(plaintext, key):
ciphertext += str(chr(ord(p)^ ord(k)))
return ciphertext
def decrypt(ciphertext, key):
for c, k in zip(ciphertext, key):
decrypted_text = str(chr(ord(c)^ ord(k)))
return decrypted_text
# Example usage
if __name__=="__main__":
plaintext = "HELLO"
key = generate_key(len(plaintext))
print("Plaintext:", plaintext)
print("Key:", key)
ciphertext = encrypt(plaintext, key)
print("Ciphertext:", ciphertext)
decrypted_text = decrypt(ciphertext, key)
print("Decrypted Text:", decrypted_text)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!