finalizando trabalho 1

This commit is contained in:
José Henrique 2023-08-30 23:03:29 -03:00
parent af82d8cd38
commit 0fe04fb3ff
1 changed files with 16 additions and 5 deletions

View File

@ -1,15 +1,23 @@
import sys
if len(sys.argv) != 3:
print("Usage: python3 vernam.py [key] [string]")
print("Usage: python3 vernam.py [arquivo de chave] [arquivo string]")
sys.exit(1)
key = sys.argv[1]
string = sys.argv[2]
key = open(sys.argv[1], 'r', newline='\n').read()
string = open(sys.argv[2], 'r', newline='\n').read()
if len(string) != len(key):
print("Key and string must have the same length")
sys.exit(1)
print(f"Key and string must have the same length [{len(string)}] vs [{len(key)}]")
print("Generating random key...")
import random
key = ""
for i in range(len(string)):
key += chr(random.randint(0, 255))
with open('key.txt', 'w+', newline='\n') as f:
f.write(key)
print("Key generated and saved to [key.txt]")
encrypted = ""
@ -19,4 +27,7 @@ for i in range(len(string)):
print(encrypted)
with open('vernam.txt', 'w+', newline='\n') as f:
f.write(encrypted)
# python3 vernam.py ABCDEF TOMATE | xargs python3 vernam.py ABCDEF