-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·29 lines (29 loc) · 944 Bytes
/
main.py
File metadata and controls
executable file
·29 lines (29 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
# realistic sample - non destructive
import argparse, base64, hashlib, json, random, time
def encode_b64(s): return base64.b64encode(s.encode()).decode()
def md5(s): return hashlib.md5(s.encode()).hexdigest()
def demo(n=5):
out=[]
for i in range(n):
s=f"demo-{int(time.time())}-{random.randint(1000,9999)}"
out.append({"in":s,"b64":encode_b64(s),"md5":md5(s)})
return out
def main():
p=argparse.ArgumentParser()
p.add_argument("action",choices=["demo","encode","md5"])
p.add_argument("value",nargs="?",default="")
p.add_argument("--json",action="store_true")
args=p.parse_args()
if args.action=="demo":
out=demo()
elif args.action=="encode":
out=encode_b64(args.value)
else:
out=md5(args.value)
if args.json:
print(json.dumps(out,indent=2,ensure_ascii=False))
else:
print(out)
if __name__=="__main__":
main()