Spaces:
Sleeping
Sleeping
Fix bug: text with from file with double endlines
Browse files
main.py
CHANGED
@@ -56,7 +56,13 @@ def create_args():
|
|
56 |
"--msg", type=str, required=True, help="Path to file containing message"
|
57 |
)
|
58 |
parser.add_argument(
|
59 |
-
"--prompt", type=str,
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
)
|
61 |
# Mode
|
62 |
parser.add_argument(
|
@@ -67,6 +73,12 @@ def create_args():
|
|
67 |
"--decrypt",
|
68 |
action="store_true",
|
69 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
return parser.parse_args()
|
72 |
|
@@ -88,6 +100,8 @@ def main(args):
|
|
88 |
private_key = None
|
89 |
|
90 |
if args.encrypt:
|
|
|
|
|
91 |
if os.path.isfile(args.msg):
|
92 |
with open(args.msg, "rb") as f:
|
93 |
msg = f.read()
|
@@ -118,11 +132,31 @@ def main(args):
|
|
118 |
salt_key=salt_key,
|
119 |
private_key=private_key,
|
120 |
)
|
121 |
-
args.text = text
|
122 |
-
|
123 |
print(f"Text contains message:\n{text}")
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
if args.decrypt:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
msgs = decrypt(
|
127 |
tokenizer=tokenizer,
|
128 |
device=args.device,
|
|
|
56 |
"--msg", type=str, required=True, help="Path to file containing message"
|
57 |
)
|
58 |
parser.add_argument(
|
59 |
+
"--prompt", type=str, default=None, help="Prompt used to generate text"
|
60 |
+
)
|
61 |
+
parser.add_argument(
|
62 |
+
"--text",
|
63 |
+
type=str,
|
64 |
+
default=None,
|
65 |
+
help="Text contains the hidden message",
|
66 |
)
|
67 |
# Mode
|
68 |
parser.add_argument(
|
|
|
73 |
"--decrypt",
|
74 |
action="store_true",
|
75 |
)
|
76 |
+
parser.add_argument(
|
77 |
+
"--save-file",
|
78 |
+
type=str,
|
79 |
+
default="",
|
80 |
+
help="Where to save output",
|
81 |
+
)
|
82 |
|
83 |
return parser.parse_args()
|
84 |
|
|
|
100 |
private_key = None
|
101 |
|
102 |
if args.encrypt:
|
103 |
+
if len(args.prompt) == 0:
|
104 |
+
raise ValueError("Prompt cannot be empty in encrypt mode")
|
105 |
if os.path.isfile(args.msg):
|
106 |
with open(args.msg, "rb") as f:
|
107 |
msg = f.read()
|
|
|
132 |
salt_key=salt_key,
|
133 |
private_key=private_key,
|
134 |
)
|
|
|
|
|
135 |
print(f"Text contains message:\n{text}")
|
136 |
|
137 |
+
if os.path.isfile(args.save_file):
|
138 |
+
with open(args.save_file, "w") as f:
|
139 |
+
f.write(text)
|
140 |
+
|
141 |
+
args.text = text
|
142 |
+
|
143 |
if args.decrypt:
|
144 |
+
if len(args.text) == 0:
|
145 |
+
raise ValueError("Text cannot be empty in decrypt mode")
|
146 |
+
if os.path.isfile(args.text):
|
147 |
+
with open(args.text, "r") as f:
|
148 |
+
lines = f.readlines()
|
149 |
+
args.text = "".join(lines)
|
150 |
+
print("=" * os.get_terminal_size().columns)
|
151 |
+
print("Encryption Parameters:")
|
152 |
+
print(f" GenModel: {args.gen_model}")
|
153 |
+
print(f" Text: {args.text}")
|
154 |
+
print(f" Message Base: {args.msg_base}")
|
155 |
+
print(f" Seed Scheme: {args.seed_scheme}")
|
156 |
+
print(f" Window Length: {args.window_length}")
|
157 |
+
print(f" Salt Key: {salt_key}")
|
158 |
+
print(f" Private Key: {private_key}")
|
159 |
+
print("=" * os.get_terminal_size().columns)
|
160 |
msgs = decrypt(
|
161 |
tokenizer=tokenizer,
|
162 |
device=args.device,
|