Skip to content

Instantly share code, notes, and snippets.

@4k1
Created October 29, 2017 11:59
Show Gist options
  • Save 4k1/ea7aff2c8ff17ad8836aa1397254fdb7 to your computer and use it in GitHub Desktop.
Save 4k1/ea7aff2c8ff17ad8836aa1397254fdb7 to your computer and use it in GitHub Desktop.
Simply Passphrase Hider / Simply hide passphrases into a characters desert.
#! /usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import string
import random
import os
def genkey(n):
return ''.join([random.choice(string.ascii_letters + string.digits) for i in range(n)])
argv = sys.argv
argc = len(argv)
if (argc != 3):
print 'Usage: %s -a password | -l keyid | -m length' % argv[0]
print ' -a Add key to keyfile.'
print ' -l Load key of keyid.'
print ' -m Make new key randomized.'
quit()
try:
f = open(os.environ['HOME'] + '/.keydata')
line = f.read()
f.close()
except:
print ('Error: File `~/.keydata` is not found. Make the file first. (ex: touch ~/.keydata)')
quit()
if (argv[1] == '-a'):
print 'key(retype):',
pw2 = raw_input()
if (argv[2] != pw2):
print '[-] Password mismatch.'
quit()
hv = genkey(random.randint(3,200))
fv = genkey(random.randint(20,180))
print ('[ ] RandomHeaderLen: %d, KeyLen: %d, RandomFooterLen: %d' % (len(hv), len(pw2), len(fv)))
f = open(os.environ['HOME'] + '/.keydata', 'a')
f.write(hv + pw2 + fv)
f.close()
print ('[+] New password has registered.')
print ('[+] keyid = %d-%d' % (len(line) + len(hv), len(pw2)))
quit()
elif (argv[1] == '-l'):
v = argv[2].split('-')
print ('[ ] Locate: %s, Length: %s' % (v[0], v[1]))
print ('[+] ' + line[int(v[0]):int(v[0])+int(v[1])])
quit()
elif (argv[1] == '-m'):
print ('[+] ' + genkey(int(argv[2])))
quit()
else:
print ('[-] Unknown options.')
quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment