Join us on IRC @ irc.r00tsecurity.org #r00tsecurity [ Web Client ] [ Log In | Register ]  
Resource Database Index -> Source Code -> OTP Algorithm
Description // Info



Source Code

  1. import random, truerandom
  2.  
  3. alpha = map(chr, range(97,123))
  4. num = range(26)
  5.  
  6. def conv2num(string):
  7.     convmesg = []
  8.     for x in range(len(list(string))):
  9.         if list(string)[x] in alpha:
  10.             for y in num:
  11.                 if alpha[y] == list(string)[x]:
  12.                     convnum = y
  13.                     break
  14.             convmesg.append(convnum)
  15.     return convmesg
  16.  
  17. def conv2alpha(string):
  18.     convmesg = []
  19.     for x in range(len(list(string))):
  20.         if list(string)[x] in num:
  21.             for y in num:
  22.                 if num[y] == list(string)[x]:
  23.                     convchar = alpha[y]
  24.                     break
  25.             convmesg.append(convchar)
  26.     return convmesg
  27.  
  28. def encrypt(mesg):
  29.     key = []
  30.  
  31.     convmesg = conv2num(mesg)
  32.  
  33.     mylist = truerandom.getnum(0,1000,len(mesg))
  34.  
  35.     for x in range(len(mylist)):
  36.         keynum = mylist[x] % 26
  37.         key.append(keynum)
  38.  
  39.     newkey = []
  40.     for z in length:
  41.         value = key[z] + convmesg[z]
  42.         while value >= 26:
  43.             value = value % 26
  44.         newkey.append(value)
  45.  
  46.     crypto = \"\"
  47.    for a in length:
  48.        crypto += alpha[newkey[a]]
  49.  
  50.    alphakey1 = conv2alpha(key)
  51.    alphakey = \"\"
  52.    for d in length:
  53.        alphakey += alphakey1[d]
  54.  
  55.    return crypto, alphakey
  56.  
  57. def decrypt(key,crypto):
  58.    key = conv2num(key)
  59.    crypto = conv2num(crypto)
  60.  
  61.    newval = []
  62.    for a in length:
  63.        newval.append(crypto[a]-key[a])
  64.  
  65.    message = []
  66.    for b in length:
  67.        message.append(newval[b] % 26)
  68.  
  69.    message = conv2alpha(message)
  70.    mesg = \'\'
  71.    for c in length:
  72.        mesg += message[c]
  73.  
  74.    return mesg
  75.  
  76. print \'\\t\\t\\tOTP Algorithm\'
  77. print \'\\t\\t\\t\\tBy: PhreakerD7\'
  78. invalid = list(\'~!@#$%^&*()`1234567890,./?<>;:\\\'\"\\\\=+-_ \\n\\t\')
  79. while True:
  80.    option = raw_input(\"\\nTo encrypt text, hit (1)\\nTo decrypt a message, hit (2)\\nTo encrypt a file, hit (3)\\nTo decrypt a file, hit (4)\\nTo exit, hit (5)\\n\\n>> \")
  81.    if option == \'1\':
  82.        message = raw_input(\"Message: \").lower()
  83.        checkmsg = list(message)
  84.        for x in range(len(checkmsg)):
  85.            if checkmsg[x] in invalid:
  86.                checkmsg[x] = \'\'
  87.        mesg = \'\'
  88.        for l in range(len(checkmsg)):
  89.            mesg += checkmsg[l]
  90.        length = range(len(mesg))
  91.        results = encrypt(mesg)
  92.        print \"Crypted Text:\", results[0]
  93.        print \"Key:\", results[1]
  94.        file2 = open(\'OTPtemp.txt\', \'w\')
  95.        file2.write(\'Crypted Text: \' + results[0] + \'\\n\\nKey: \' + results[1])
  96.        file2.close()
  97.    elif option == \'2\':
  98.        crypto = raw_input(\"Crypted Text: \")
  99.        key = raw_input(\"Key: \")
  100.        length = range(len(crypto))
  101.        text = decrypt(key, crypto)
  102.        print \"Decrypted Text:\", text
  103.    elif option == \'3\':
  104.        filename = raw_input(\'File name>> \')
  105.        file2 = open(filename, \'r\')
  106.        data = file2.read().lower()
  107.        file2.close()
  108.        checkmsg = list(data)
  109.        for x in range(len(checkmsg)):
  110.            if checkmsg[x] in invalid:
  111.                checkmsg[x] = \'\'
  112.        mesg = \'\'
  113.        for l in range(len(checkmsg)):
  114.            mesg += checkmsg[l]
  115.        length = range(len(mesg))
  116.        results = encrypt(mesg)
  117.        encryptfile = filename.split(\'.\')[0] + \'.enc\'
  118.        keyfile = filename.split(\'.\')[0] + \'.key\'
  119.        file2 = open(encryptfile, \'w\')
  120.        file2.write(results[0])
  121.        file2.close()
  122.        file2 = open(keyfile, \'w\')
  123.        file2.write(results[1])
  124.        file2.close()
  125.        print \'[*] Encrypted file at:\', encryptfile
  126.        print \'[*] Key file at:\', keyfile
  127.    elif option == \'4\':
  128.        filename = raw_input(\'Encrypted File name>> \')
  129.        keyfile = raw_input(\'Key file name>> \')
  130.        file2 = open(filename, \'r\')
  131.        data = file2.read()
  132.        file2.close()
  133.        file2 = open(keyfile, \'r\')
  134.        crypto = file2.read()
  135.        file2.close()
  136.        length = range(len(data))
  137.        text = decrypt(crypto,data)
  138.        decryptfile = filename.split(\'.\')[0] + \'.dec\'
  139.        file2 = open(decryptfile, \'w\')
  140.        file2.write(text)
  141.        file2.close()
  142.        print \'[*] Plain-Text file at:\', decryptfile
  143.    elif option == \'5\':
  144.        break


Comments

You must be logged in to post comments.

 Network Access...
USER ID
PASSWORD

 Code Information
Language:
Python

Version:
1.0


Submitted:
2009-10-09 - 20:26:49


Author:
PhreakerD7
E-Mail
Website

Greetz:


[ Download | Report Issue ]

 Code Search
Search by Language
+ Assembly
+ ASP
+ ASP.NET
+ C#
+ C/C++
+ Cobol
+ Delphi
+ Java
+ Javascript
+ Pascal
+ Perl
+ PHP
+ Python
+ VB6
+ VB.NET

Advanced Search




 
By continuing past this page, and by your continued use of this site, you agree to be bound by and abide by the User Agreement.

© 2008 r00tsecurity network. All rights reserved.
[ About Us | Contact Us | Support Us | Legal | Advertise | User Agreement | Privacy Policy ]