Add some stuff from yesterday

This commit is contained in:
BBaoVanC 2021-05-14 10:11:09 -05:00
parent 89c2919008
commit d025209854
Signed by: bbaovanc
GPG Key ID: 18089E4E3CCF1D3A
6 changed files with 114 additions and 0 deletions

26
144/rot13.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import sys
import string
rawInput = sys.stdin.read()
output = ""
for c in rawInput:
if c in string.ascii_lowercase:
letters = string.ascii_lowercase
elif c in string.ascii_uppercase:
letters = string.ascii_uppercase
else:
output += c
continue
i = letters.index(c)
if i > 12:
i -= 13
else:
i += 13
output += letters[i]
print(output)

1
156/decode.py Symbolic link
View File

@ -0,0 +1 @@
../22/decode.py

1
166/a.txt Normal file
View File

@ -0,0 +1 @@
gAAAAABgUAIWIvSiR0W23DAHIK5DX6Y4BvwES94M_XdDcNAquhp-A0D2z8n812YEXaSD9WhoweBh2cm5Wa0cqzuW0Kc7fOct0OJnpOmVF8A91j0Hx4dKtvk3l5ghPT71Y7GxErPRyJUs

61
166/ende.py Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env python3
import sys
import base64
from cryptography.fernet import Fernet
usage_msg = "Usage: "+ sys.argv[0] +" (-e/-d) [file]"
help_msg = usage_msg + "\n" +\
"Examples:\n" +\
" To decrypt a file named 'pole.txt', do: " +\
"'$ python "+ sys.argv[0] +" -d pole.txt'\n"
if len(sys.argv) < 2 or len(sys.argv) > 4:
print(usage_msg)
sys.exit(1)
if sys.argv[1] == "-e":
if len(sys.argv) < 4:
sim_sala_bim = input("Please enter the password:")
else:
sim_sala_bim = sys.argv[3]
ssb_b64 = base64.b64encode(sim_sala_bim.encode())
c = Fernet(ssb_b64)
with open(sys.argv[2], "rb") as f:
data = f.read()
data_c = c.encrypt(data)
sys.stdout.write(data_c.decode())
elif sys.argv[1] == "-d":
if len(sys.argv) < 4:
sim_sala_bim = input("Please enter the password:")
else:
sim_sala_bim = sys.argv[3]
ssb_b64 = base64.b64encode(sim_sala_bim.encode())
c = Fernet(ssb_b64)
with open(sys.argv[2], "r") as f:
data = f.read()
data_c = c.decrypt(data.encode())
sys.stdout.buffer.write(data_c)
elif sys.argv[1] == "-h" or sys.argv[1] == "--help":
print(help_msg)
sys.exit(1)
else:
print("Unrecognized first argument: "+ sys.argv[1])
print("Please use '-e', '-d', or '-h'.")

BIN
186/cat.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 858 KiB

25
22/decode.py Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import sys
rawInput = sys.stdin.readlines()
splitInput = [l.strip() for l in rawInput]
for c in splitInput:
try:
int(c)
is_int = True
except ValueError:
is_int = False
assert is_int, "Input must be in decimal form, and separated by newlines"
rawOutput = []
for c in splitInput:
c2 = chr(int(c))
rawOutput.append(c2)
output = ""
for c in rawOutput:
output += c
print(output)