-
Notifications
You must be signed in to change notification settings - Fork 0
/
passphraser.py
executable file
·56 lines (44 loc) · 1.74 KB
/
passphraser.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/python3
import argparse
import sys
from lib import to_passphrase, from_passphrase
def main():
parser = argparse.ArgumentParser(
description='Encode any data as a passphrase and decode it back.')
parser.add_argument('input', nargs='?', default=None,
help='Value to encode. Could be read from standard input.')
parser.add_argument('-d', '--decode', action='store_true')
parser.add_argument('-m', '--mode', default='hex',
help='Specify how to parse input. Possible values: hex, ascii.')
parser.add_argument('-w', '--wordlist', default='bip39')
parser.add_argument('-v', '--verbose', action='store_true')
args = parser.parse_args()
stdin_present = stdin_is_present()
if args.input:
input_str = args.input
if stdin_present:
print('[Warning] Ignoring standard input since argument was provided.')
else:
if not stdin_present:
print('Enter the value:')
input_str = sys.stdin.readline().strip()
if not input_str:
print('[Error] No input provided.')
sys.exit(1)
if args.decrypt:
result = from_passphrase(input_str,
mode=args.mode,
wordlist_option=args.wordlist,
verbose=args.verbose)
else:
result = to_passphrase(input_str,
mode=args.mode,
wordlist_option=args.wordlist,
verbose=args.verbose)
print(f'[Result] {result}', file=sys.stdout)
def stdin_is_present():
if not sys.stdin.isatty():
return True
return False
if __name__ == '__main__':
main()