> For the complete documentation index, see [llms.txt](https://cajac.gitbook.io/ctf-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cajac.gitbook.io/ctf-notes/crypto/hashing/hashing-in-python.md).

# Hashing in Python

## Examples

### Hashing script #1

Script example #1 from picoCTF

```python
#!/usr/bin/python
# -*- coding: latin-1 -*-

import hashlib
from pwn import *
import re

SERVER = 'saturn.picoctf.net'
PORT = 55823

def generateHash(word): 
    return hashlib.md5(word.encode()).hexdigest()

conn = remote(SERVER, PORT)
for i in range(3):
    question = conn.recvline().decode().strip()
    word = re.findall('Please md5 hash the text between quotes, excluding the quotes: \'(.*)\'', question)[0]
    answer = conn.recvline()
    hash = generateHash(word).encode()
    conn.sendline(hash)
    hashline = conn.recvline()
    correct = conn.recvline()
flag = conn.recvline().decode().strip()
conn.close()
print(flag)
```

## Resources

hashlib module - Python: <https://docs.python.org/3/library/hashlib.html>
