import sys, hashlib, getopt
def hashCal(argv):
string=''
salt=''
option=''
try:
opts, args = getopt.getopt(argv,"s:x:o:")
except:
print_usage()
sys.exit()
for opt, arg in opts:
if(opt=='-h'):
print_help()
sys.exit()
elif(opt=='-s'):
string = arg
elif(opt=='-o'):
option = arg
print "Entered String: %s" % (string)
print "Your Selection: %s" % (option)
if(option == 'md5'):
m = hashlib.md5()
elif(option == 'sha1'):
m = hashlib.sha1()
m.update(string)
print "%s Encrypted strng: %s" %(option, str(m.digest()))
def print_usage():
print "usage: encryption.py -s <string> -o <option>(eg: sha1,md5)"
def print_help():
print "usage: encryption.py -s <string> -o <option> -o <options>: \nmd5\nsha1"
if __name__ == "__main__":
try:
if len(sys.argv) == 1:
raise
argvs = sys.argv[1:]
except:
print_usage()
sys.exit()
hashCal(argvs)
OUTPUT:
root@Avinash:~/python_codes/Security# python encryption.py
usage: encryption.py -s <string> -o <option>(eg: sha1,md5)root@Avinash:~/python_codes/Security# python encryption.py -s 'avinash' -o 'sha1'
Entered String: avinash
Your Selection: sha1
�U\�N)��r �Fed strng: T� �,ifroot@Avinash:~/python_codes/Security# root@Avinash:~/python_codes/Security# python encryption.py -s 'avinash' -o 'md5'
Entered String: avinash
Your Selection: md5
md5 Encrypted strng: ��u 0�)�Fk
h9kroot@Avinash:~/python_codes/Security#
def hashCal(argv):
string=''
salt=''
option=''
try:
opts, args = getopt.getopt(argv,"s:x:o:")
except:
print_usage()
sys.exit()
for opt, arg in opts:
if(opt=='-h'):
print_help()
sys.exit()
elif(opt=='-s'):
string = arg
elif(opt=='-o'):
option = arg
print "Entered String: %s" % (string)
print "Your Selection: %s" % (option)
if(option == 'md5'):
m = hashlib.md5()
elif(option == 'sha1'):
m = hashlib.sha1()
m.update(string)
print "%s Encrypted strng: %s" %(option, str(m.digest()))
def print_usage():
print "usage: encryption.py -s <string> -o <option>(eg: sha1,md5)"
def print_help():
print "usage: encryption.py -s <string> -o <option> -o <options>: \nmd5\nsha1"
if __name__ == "__main__":
try:
if len(sys.argv) == 1:
raise
argvs = sys.argv[1:]
except:
print_usage()
sys.exit()
hashCal(argvs)
OUTPUT:
root@Avinash:~/python_codes/Security# python encryption.py
usage: encryption.py -s <string> -o <option>(eg: sha1,md5)root@Avinash:~/python_codes/Security# python encryption.py -s 'avinash' -o 'sha1'
Entered String: avinash
Your Selection: sha1
�U\�N)��r �Fed strng: T� �,ifroot@Avinash:~/python_codes/Security# root@Avinash:~/python_codes/Security# python encryption.py -s 'avinash' -o 'md5'
Entered String: avinash
Your Selection: md5
md5 Encrypted strng: ��u 0�)�Fk
h9kroot@Avinash:~/python_codes/Security#
No comments:
Post a Comment