Skip to content

Instantly share code, notes, and snippets.

@atoponce
Last active July 6, 2024 23:34
Show Gist options
  • Save atoponce/af8581397315dfbee490 to your computer and use it in GitHub Desktop.
Save atoponce/af8581397315dfbee490 to your computer and use it in GitHub Desktop.
Encryption and decryption with SHA-256
#!/usr/bin/python
import hashlib
nonce = 0
key = 'f3q4uszyt67cfatq'
pad = hashlib.sha256(str(nonce)+key).digest()
# encrypt
plaintext = 'the quick brown fox jumped over.'
ciphertext = ''
for i in range(32):
ciphertext += chr(ord(pad[i])^ord(plaintext[i]))
# ciphertext = '\x1bf\x13\r\x0c\xc4\x18`\x129\x16\x12|\x96\xa7\xc2\xf5E_\x97\xc2\x010\x88]j\xce\xe3x\x14\xe8\xb6'
# decrypt
plaintext = ''
for i in range(32):
plaintext += chr(ord(pad[i]^ord(ciphertext[i]))
# plaintext = 'the quick brown fox jumped over.'
@sagor073
Copy link

4d07cfd21cb3b4c6c2aedb05456f5299629ea7b6b80a48004d3ef5e06b8d9e25

@sagor073
Copy link

4d07cfd21cb3b4c6c2aedb05456f5299629ea7b6b80a48004d3ef5e06b8d9e25

@qazzaq666
Copy link

I got "azerty"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment