MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

  • Python
  • pycrypto

pycrypto

Collection of both secure hash functions (such as MD5 and SHA), and various encryption algorithms (AES, DES, IDEA, RSA, ElGamal, etc.).

SlackBuild

  • su
  • cd /tmp
  • wget http://slackbuilds.org/slackbuilds/14.1/python/pycrypto.tar.gz

  • tar xvzf pycrypto.tar.gz
  • cd pycrypto
  • wget http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.1.tar.gz

  • ./pycrypto.SlackBuild

  • installpkg /tmp/pycrypto-2.6.1-i486-1_SBo.tgz

Sample code

   1 from Crypto.Cipher import ARC4
   2 from Crypto.Cipher import AES
   3 from Crypto.Cipher import XOR
   4 from Crypto import Random
   5 
   6 texts=['1234','1234','01234A','ABC','ABC','CCCCCCC','CCCCCCC']
   7 
   8 def getHex(data):
   9     ret=''
  10     for c in data:
  11         ret='%s%02X'%(ret,ord(c))
  12     return ret
  13 
  14 def testARC4(key):
  15     print '= ARC4 ='
  16     cipher = ARC4.new(key)
  17     encrypted=[]
  18     for text in texts:
  19         encx=cipher.encrypt(text)
  20         encrypted.append(encx)
  21         print 'Orig:%s Encrypted:%s'%(text,getHex(encx))
  22 
  23     cipherDec = ARC4.new(key)
  24     for encd in encrypted:
  25         decrypted = cipherDec.decrypt(encd)
  26         print 'Decrypted:%s'%(decrypted)
  27 
  28 def testAES1(key):
  29     print '= AES ='
  30     iv = Random.new().read(AES.block_size)
  31     print 'IV: %s'%(getHex(iv))
  32     cipher = AES.new(key,AES.MODE_CFB,iv)
  33     encrypted=[]
  34     for text in texts:
  35         encx=cipher.encrypt(text)
  36         encrypted.append(encx)
  37         print 'Orig:%s Encrypted:%s'%(text,getHex(encx))
  38 
  39     cipherDec = AES.new(key,AES.MODE_CFB,iv)
  40     for encd in encrypted:
  41         decrypted = cipherDec.decrypt(encd)
  42         print 'Decrypted:%s'%(decrypted)
  43 
  44 def testXOR(key):
  45     print '= XOR ='
  46     cipher = XOR.new(key)
  47     encrypted=[]
  48     for text in texts:
  49         encx=cipher.encrypt(text)
  50         encrypted.append(encx)
  51         print 'Orig:%s Encrypted:%s'%(text,getHex(encx))
  52 
  53     cipherDec = XOR.new(key)
  54     for encd in encrypted:
  55         decrypted = cipherDec.decrypt(encd)
  56         print 'Decrypted:%s'%(decrypted)
  57 
  58 
  59 if __name__=='__main__':
  60     key='1234567890123456'
  61     testARC4(key) 
  62     testAES1(key)
  63     testXOR(key)
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01