I am making using linear congruential generator to generate the keystream and then I will use this keystream to encrypt and decrypt the plaintext.I am trying to generate 47 pseudorandom number the Plaintext will be "Meetmeattownhallatsevenpmforpaymentandbringbear" The length of the keystream need to be the same as length of the plaintext. Then we map the numbers generated to the alphabets in the look-up alphabet.
I am creating a python script to perform the Linear congruential generator to produce the keystream. I am attempting to encrypt the plaintext, "Get ready to meet at town hall at 5pm". I am having trouble doing this. I am using the algorithm for the linear congruential generator below
Xn+1 = (aXn + c) mod m
where Xn is the sequence of pseudorandom values, and
• Modulus: m, 0 < m
• Multiplier: a, 0 < a < m
• Increment: c, 0 ≤ c < m
• Seed: X0, 0 ≤ X0 < m
Python Code
# Initialize the seed state
#!/usr/bin/env python#!/usr/bin/env python3
def linearCongruentialGenerator(Xo, m, a, c,randomNums,noOfRandomNums):
# Initialize the seed state
randomNums[0] = Xo
# Traverse to generate required
# numbers of random numbers
for i in range(1, noOfRandomNums):
# Follow the linear congruential method
randomNums[i] = ((randomNums[i - 1] * a) +
c) % m
#Main function
if __name__ == '__main__':
# Seed value
Xo = 27
# Modulus parameter
m = 100
# Multiplier term
a = 17
# Increment term
c = 43
# Number of Random numbers
# to be generated
noOfRandomNums = 47
#Variable to declare the randomnumber
randomNums = [0] * (noOfRandomNums)
#Call the function
linearCongruentialGenerator(Xo, m, a, c,randomNums,noOfRandomNums)
# Print the generated random numbers
for i in randomNums:
print(i, end = " ")
I want the output to be something like this.
Could you kindly help me in the linear congruential generator python to generate keystream to encrypt and decrypt the plaintext and how to map the numbers generated to the characters of the plaintext.
Thank you