-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateMessages.py
More file actions
31 lines (25 loc) · 1.19 KB
/
Copy pathcreateMessages.py
File metadata and controls
31 lines (25 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import random
def replaceChar(s, index, new_char):
s[index] = new_char
def generateCipher(inputMessage):
encodedLetters = {}
availableAlpha = list("abcdefghijklmnopqrstuvwxyz")
output = []
for letter in inputMessage:
if letter.isalpha():
if letter not in encodedLetters:
random.shuffle(availableAlpha) # Shuffle to improve randomness
randomChar = next((ch for ch in availableAlpha if ch != letter), availableAlpha[0])
encodedLetters[letter] = randomChar
availableAlpha.remove(randomChar) # Remove assigned letter
output.append(encodedLetters[letter])
else:
output.append(letter)
return "".join(output)
# the quick brown fox jumps over the lazy dog while the zebras and the wolves zigzag through fields, fetching jugs of mixed liquor and hefty boxes.
# a jittery mouse vexed a dozing cat while big frogs and quirky zebras hopped over waxy boxes filled with mixed liquid and junk.
if __name__=="__main__":
inputMessage = input("Encrypted Message: ").lower()
for i in range(100):
outputMessage = generateCipher(inputMessage)
print(outputMessage)