Tag Archives: Cryptography

Cours de cryptographie de l’université de Stanford

Attention ça ne déconne plus, des cours de Stanford gratis. Mais vous n’aurez pas de certification. Que pour le plaisir ;-)

Il y a maintenant une date plus précise. Les cours commenceront le 23 janvier 2012, en ce qui concerne la cryptographie. C’est l’occasion de tester ses connaissances. Ou même d’apprendre car le cours devrait être autosuffisant.

Pure Python RSA implementation compatible OpenSSL

$ sudo aptitude install python-pyasn1
$ hg clone https://bitbucket.org/sybren/python-rsa/
$ cd python-rsa
$ sudo python setup.py install
$ cd ..

# Generation of a private key:
$ openssl genrsa -out myprivatekey.pem 512


# To get a Python-RSA-compatible public key from OpenSSL:
$ pyrsa-priv2pub -i myprivatekey.pem -o mypublickey.pem

# Get a public key with the standard method:
$ openssl rsa -in myprivatekey.pem -out public.pem -outform PEM -pubout
writing RSA key


# Test 1: Python-RSA-compatible public key
$ echo hello there > testfile.txt
$ pyrsa-encrypt -i testfile.txt -o testfile.rsa mypublickey.pem
Reading public key from mypublickey.pem
Reading input from testfile.txt
Encrypting
Writing output to testfile.rsa
$ openssl rsautl -in testfile.rsa -inkey myprivatekey.pem -decrypt
hello there


# Test 2: standard public key
$ openssl rsautl -encrypt -inkey public.pem -pubin -in testfile.txt -out file.ssl
$ pyrsa-decrypt -i file.ssl -o file.txt myprivatekey.pem 
Reading private key from myprivatekey.pem
Reading input from file.ssl
Decrypting
Writing output to file.txt
$ cat file.txt 
hello there

C’est le module Python RSA que j’utilise en général.

pySecret

you@debian:~$ hg clone http://bitbucket.org/cedricbonhomme/pysecret
you@debian:~$ ipython
In [1]: from pysecret import permutation
In [2]: permutation.encrypt("Python est un très bon language!", [2,4,0,1,3])
Out[2]: 'toPyhetn snt u \xa8 r\xc3snlbo gaanu!XgeX'
In [3]: print permutation.decrypt(permutation.encrypt("Python est un très bon language!", [2,4,0,1,3]), [2,4,0,1,3])
Python est un très bon language!XX
In [4]: from pysecret import rsa
In [5]: rsa_cipher = rsa.RSA()
In [6]: rsa_cipher.decrypt_text("eJwNjrsRw1AMw3pPksonUqQ+O3gJ9ymyf5VXEzjw8/3hehgloJwwmO0eAxFFbW8oc7MrpyowuWLk\nmZVuzn
AstTCUcppNL1yaQcoQNx1NxbSPq8YUaCzqEO6UVMsk4mSb54lI1kmsn+u9/9cOIaE=")
Out[6]: 'Il reste encore beaucoup de travail!'
In [7]: exit()
Do you really want to exit ([y]/n)? y
you@debian:~$ ls -l pysecret/
total 140
-rwx------ 1 you you  1356 2010-09-26 18:23 afine.py
-rwx------ 1 you you   883 2010-09-26 18:24 autokeycipher.py
-rwx------ 1 you you   774 2010-09-26 18:06 cesar.py
-rwx------ 1 you you 35146 2010-04-29 22:32 COPYING
-rwx------ 1 you you  1921 2010-09-26 18:19 elgamal.py
-rwx------ 1 you you  1299 2010-09-26 18:21 hill.py
-rwx------ 1 you you     2 2010-09-26 18:14 __init__.py
-rwx------ 1 you you  1629 2010-09-26 18:26 permutation.py
-rwx------ 1 you you  1704 2010-09-26 18:26 rabin.py
-rwx------ 1 you you  6402 2010-09-26 18:07 rsa_gui.py
-rwx------ 1 you you  3824 2010-09-26 18:26 rsa.py
-rwx------ 1 you you   908 2010-09-26 18:28 substitution.py
-rwx------ 1 you you 10420 2010-09-26 18:28 utils.py
-rwx------ 1 you you  2234 2009-02-26 22:06 vigenere.py