This commit is contained in:
billbuchanan
2023-02-07 19:27:55 +00:00
3 changed files with 65 additions and 12 deletions

View File

@@ -16,9 +16,9 @@ The key concepts involved are defining key entropy; key generators (such as usin
## Presentations
* Week 2 Presentation (PPTX) - Symmetric Key Encryption: [here](https://github.com/billbuchanan/appliedcrypto/blob/master/unit02_symmetric/lecture/chapter02_secret.pptx)
* Week 2 Doodle (Video) - Symmetric Key Encryption [here](https://youtu.be/kdCI5UiVl04)
* Week 2 Presentation (Video) - Symmetric Key Encryption [here](https://youtu.be/nLRV34K3xIo)
* Unit 2 Presentation (PPTX) - Symmetric Key Encryption: [here](https://github.com/billbuchanan/appliedcrypto/blob/master/unit02_symmetric/lecture/chapter02_secret.pptx)
* Unit 2 Doodle (Video) - Symmetric Key Encryption [here](https://youtu.be/FAjEn-u-qfA)
* Unit 2 Presentation (Video) - Symmetric Key Encryption [here](https://youtu.be/kdCI5UiVl04)
## Lab

View File

@@ -332,6 +332,65 @@ print(" decrypt: ",plaintext.decode())
A sample is [here](https://replit.com/@billbuchanan/desdec#main.py).
If you want to pass as arguments:
```Python
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives import padding
from cryptography.hazmat.backends import default_backend
import sys
import hashlib
import binascii
val='hello'
password='hello'
plaintext=val
def encrypt(plaintext,key, mode):
method=algorithms.TripleDES(key)
cipher = Cipher(method,mode, default_backend())
encryptor = cipher.encryptor()
ct = encryptor.update(plaintext) + encryptor.finalize()
return(ct)
def decrypt(ciphertext,key, mode):
method=algorithms.TripleDES(key)
cipher = Cipher(method, mode, default_backend())
decryptor = cipher.decryptor()
pl = decryptor.update(ciphertext) + decryptor.finalize()
return(pl)
def pad(data,size=64):
padder = padding.PKCS7(size).padder()
padded_data = padder.update(data)
padded_data += padder.finalize()
return(padded_data)
def unpad(data,size=64):
padder = padding.PKCS7(size).unpadder()
unpadded_data = padder.update(data)
unpadded_data += padder.finalize()
return(unpadded_data)
if (len(sys.argv)>1):
digest=str(sys.argv[1])
if (len(sys.argv)>2):
password=str(sys.argv[2])
key = hashlib.sha256(password.encode()).digest()[:16]
ciphertext=binascii.unhexlify(digest)
plaintext = decrypt(ciphertext,key,modes.ECB())
plaintext = unpad(plaintext)
print(" decrypt: ",plaintext.decode())
```
### E.3
In this case we will convert from Base-64 into a byte array and then try to decrypt:

View File

@@ -14,14 +14,8 @@ The key concepts involved in this unit are:
## Presentations
* Week 2 Presentation (PDF) - Symmetric Key Encryption: [here](https://asecuritysite.com/public/chapter02_secret.pdf)
* Week 2 Presentation (Video) - Symmetric Key Encryption [here](https://youtu.be/kdCI5UiVl04)
## Videos
The voice over lecture is here:
[![](http://img.youtube.com/vi/kdCI5UiVl04/0.jpg)](https://www.youtube.com/watch?v=kdCI5UiVl04 "")
* Unit 2 Presentation (PPTX) - Symmetric Key Encryption: [here](https://github.com/billbuchanan/appliedcrypto/blob/master/unit02_symmetric/lecture/chapter02_secret.pptx)
* Unit 2 Doodle (Video) - Symmetric Key Encryption [here](https://youtu.be/FAjEn-u-qfA)
* Unit 2 Presentation (Video) - Symmetric Key Encryption [here](https://youtu.be/kdCI5UiVl04)