Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python code needed: The goal of this project is to implement the One-Time Pad. O

ID: 3805611 • Letter: P

Question

Python code needed: The goal of this project is to implement the One-Time Pad.
Optional psuedocode:
def KeyGen(n): Initialize a key to an empty string
For each item in range (n): Append a random bit to the key

Return the key 2 Challenge 1: KeyGen Write a function which generates the key for the OTP. This key should be randomly generated. For this, you must use the random module. The function should have input n, the desired key length, and output an n-bit random binary key INPUT: integer n OUTPUT: n-bit binary string Example: Input 3 output 110 Input 5 output 10110 Input 10, output 001 1000101

Explanation / Answer

Following is the python code for the above question:

import random
def KeyGen(n):
var=""
for k in range(0,n):
x=random.randint(0,1)
x=str(x)
var=var+x
return var
a = None
while a is None:
try:
a = int(input("Enter a number: "))
except ValueError:
print("Not an integer value...")
print(KeyGen(a))