gh copilot realness

This commit is contained in:
lda committed 2025-05-16 22:43:53 +07:00
1 parent 039af0b541
commit 78307d3d59
1 file changed
+67 -21
+67 -21
View File
@@ -1,20 +1,33 @@
"""
asscryption: Proof-of-concept random key-based text transformer.
USAGE:
Encrypt: python main.py encrypt <filein> <target> [--seed SEED] > keyfile
filein: Input text file (plaintext)
target: Target text file (what you want to transform to)
--seed: (Optional) Random seed for reproducibility
keyfile: Output key file (redirect stdout)
Decrypt: python main.py decrypt <filein> <keyfile>
filein: Input text file (should match the target used in encrypt)
keyfile: Key file produced during encryption
EXAMPLES:
python main.py encrypt message.txt target.txt --seed 42 > mykey.txt
python main.py decrypt target.txt mykey.txt
NOTES:
- This is a proof-of-concept. The "key" is printed to stdout during encryption.
- The target file must exist and be the same length as the input.
"""
from itertools import repeat from itertools import repeat
import random import random
import argparse import argparse
import difflib
from typing import Generator, Tuple from typing import Generator, Tuple
parser = argparse.ArgumentParser(
description="program that makes random ass keys for transformation of text"
)
## there is input file, output file and potentially a list of numbers from -256 to 256.
def index_list(range: range, length: int, seed=None) -> Generator[int, None, None]: def index_list(range: range, length: int, seed=None) -> Generator[int, None, None]:
"put in a range obj (`range(1, 19, 2)`) for range"
if seed is not None: if seed is not None:
random.seed(seed) random.seed(seed)
return (random.choice(range) for _ in repeat(None, length)) return (random.choice(range) for _ in repeat(None, length))
@@ -37,17 +50,50 @@ def rebuild(text_in, this: Generator[Tuple[int, int], None, None]):
yield chr(ord(val_in) + offset) yield chr(ord(val_in) + offset)
str1 = "hello world" def main():
# str1 = input("what is the message in: ") parser = argparse.ArgumentParser(
str2 = "this shit is ass" description="asscryption: Random key-based text transformer (PoC). See top of file for usage."
# str2 = input("what is the message out: ") )
subparsers = parser.add_subparsers(dest="command", required=True)
ahh_key = list(funky_function(str1, str2)) enc = subparsers.add_parser("encrypt")
enc.add_argument("filein")
enc.add_argument("target")
enc.add_argument("--seed", type=int, default=None)
# print("the key:") dec = subparsers.add_parser("decrypt")
print(ahh_key) dec.add_argument("filein")
# [(6, -3), (7, -7), (6, -14), (5, 83), (5, 0), (0, 11), (7, -7), (8, -9), (1, 15), (6, -87), (7, -6), (6, -4), (5, 0), (6, -22), (8, 1), (4, 4)] dec.add_argument("keyfile")
# print("the key works:") args = parser.parse_args()
print("".join(rebuild(str1, (i for i in ahh_key))))
# this shit is ass if args.command == "encrypt":
# read filein
with open(args.filein, "r", encoding="utf-8") as fin:
text_in = fin.read()
# read fileout
with open(args.target, "r", encoding="utf-8") as fout:
text_out = fout.read()
# Build key
key = list(funky_function(text_in, text_out, args.seed))
# Print key to stdout
print(key)
elif args.command == "decrypt":
# read filein, read keyfile, print recovered text
with open(args.filein, "r", encoding="utf-8") as fin:
text_in = fin.read()
with open(args.keyfile, "r", encoding="utf-8") as kf:
import ast
key = ast.literal_eval(kf.read())
# Rebuild original text
result = "".join(rebuild(text_in, key))
print(result)
if __name__ == "__main__":
main()