Added support of nonterminal usage of code.

This commit is contained in:
Mikolaj Lubiak 2022-05-16 20:32:58 +02:00
parent 278475d2cc
commit c1ef1f15e7
2 changed files with 22 additions and 8 deletions

View File

@ -3,8 +3,8 @@ from rot import chars
from sys import argv
from collections import Counter
def brkc(m: str, f: str):
t=tuple(open(f).read().splitlines()[:1000])
def brkc(m: str, f: str, x: int):
t=tuple(open(f).read().splitlines()[:x])
decm=[]
for i in range(1, len(chars)):
decmsg=dec(m, i)
@ -13,7 +13,14 @@ def brkc(m: str, f: str):
if x.upper() in decmsg:
decm.append(decmsg)
return Counter(decm)
if __name__ == "__main__":
a=argv[1]
b=argv[2]
print(brkc(a, b))
try:
a=argv[1]
b=argv[2]
c=int(argv[3])
except IndexError:
a=input("Give encoded text to break: ")
b=input("Give filename of file which contains wordlist: ")
c=int(input("Type how many words to read from the wordlist ('-1'=every): "))
print(brkc(a, b, c))

13
rot.py
View File

@ -1,3 +1,5 @@
#!/usr/bin/env python3
from string import ascii_uppercase as chars
from sys import argv
@ -16,7 +18,12 @@ def decrypt(s: str, i: int):
if s[x].upper() == chars[y]:
dec+=chars[(y-i)%len(chars)]
return dec
if __name__ == "__main__":
a=argv[1]
b=int(argv[2])
print(encrypt(a, b), decrypt(a, b))
try:
a=argv[1]
b=int(argv[2])
except IndexError:
a=input("Give text to encode/decode: ")
b=int(input("Type how many shifts do you want to do: "))
print(f"Encrypted: {encrypt(a, b)}\nDecrypted: {decrypt(a, b)}")