Skip to content

Instantly share code, notes, and snippets.

@atoponce
Last active April 17, 2025 00:56
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"

@Christian-Jara
Copy link

909c30a3ac10989d33958a3bdd1193b58d217bfd5e4bebbd3c280c7580afd525

@Saitech07
Copy link

Can anyone please decrypt the below given string for me I have tried many ways.

748c46b945efabb18ef1e793b3af886518042522d55121dbf618e9da0816ec5a

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