SE Can't Code

A Tokyo based Software Engineer. Not System Engineer :(

Tips, Ipython to get hash.

It is easy for you to use hash by Ipython.

about Ipython

IPython is a rich archtecture for interactive computing which is powerful extended from Python.
It provides below;

  • Powerful interactive shells (terminal and Qt-based).
  • A browser-based notebook with support for code, text, mathematical expressions, inline plots and other rich media.
  • Support for interactive data visualization and use of GUI toolkits.
  • Flexible, embeddable interpreters to load into your own projects.
  • Easy to use, high performance tools for parallel computing.

how do hash?

Let’s start Ipython in terminal and type import command.

In [1]: import hashlib

A special feature of Ipython is function of complement. You press [TAB] key with typing below command.

In [2]: hashlib.
hashlib.algorithms hashlib.sha224 hashlib.sha384 hashlib.md5 hashlib.sha1 hashlib.sha256 hashlib.sha512

In this case, i will use hashlib.md5, type below the command.

In [3]: x = hashlib.md5("hello")
In [4]: x
In [5]: x.hexdigest()
Out[5]: '5d41402abc4b2a76b9719d911017c592'
Out[5] is hash value. And You have another way that type under the command.
In [9]: hashlib.md5("helloworld").hexdigest()
Out[9]: 'fc5e038d38a57032085441e7fe7010b0'

So MD5 is insufficiency security, because It is very easy to decode hash by malicious user who knows algorithm of using at your WebPage.There are some way which is better security than MD5. HMAC is one of those way. HMAC is a way which gives a secret key to subject of hash. Because this secret key is’t known from malicious user, you prevent decoding of hash. Let’s type below command.

In [1]: import hmac In [2]: SECRET = "secretkey"
In [3]:,"helloworld").hexdigest()
Out[3]: 'f5ea2a8229b8fdfaf207316dfd265995'

This case of HMAC is that SECRET which defined by option string appends subject of hash. I wish remember this Tips in future:)