finalizando trabalho 1
This commit is contained in:
parent
af82d8cd38
commit
0fe04fb3ff
|
@ -1,15 +1,23 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if len(sys.argv) != 3:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
key = sys.argv[1]
|
key = open(sys.argv[1], 'r', newline='\n').read()
|
||||||
string = sys.argv[2]
|
string = open(sys.argv[2], 'r', newline='\n').read()
|
||||||
|
|
||||||
if len(string) != len(key):
|
if len(string) != len(key):
|
||||||
print("Key and string must have the same length")
|
print(f"Key and string must have the same length [{len(string)}] vs [{len(key)}]")
|
||||||
sys.exit(1)
|
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 = ""
|
encrypted = ""
|
||||||
|
|
||||||
|
@ -19,4 +27,7 @@ for i in range(len(string)):
|
||||||
|
|
||||||
print(encrypted)
|
print(encrypted)
|
||||||
|
|
||||||
|
with open('vernam.txt', 'w+', newline='\n') as f:
|
||||||
|
f.write(encrypted)
|
||||||
|
|
||||||
# python3 vernam.py ABCDEF TOMATE | xargs python3 vernam.py ABCDEF
|
# python3 vernam.py ABCDEF TOMATE | xargs python3 vernam.py ABCDEF
|
||||||
|
|
Loading…
Reference in New Issue