Benford’s Law, which has applications in data science and fraud detection.
Depends on the problem:
Cyphertext | Output |
---|---|
ROT0 | To be or not to be, That is the question |
ROT1 | Up cf ps opu up cf, Uibu jt uif rvftujpo |
ROT2 | Vq dg qt pqv vq dg, Vjcv ku vjg swguvkqp |
… | … |
ROT9 | Cx kn xa wxc cx kn, Cqjc rb cqn zdnbcrxw |
ROT is known as the Caesar Cypher, but since the transformation is simple (A..Z+=x
) decryption is easy now. How can we make this harder?
See also: random.randrange
, random.choice
, random.sample
, random.random
, random.gauss
, etc.
Computers actually use pseudo-random number generators. If they are initialised with a seed the will generate the same sequence.
Two main libraries where seeds are set:
Where would you use a mix of randomness and reproducbility as part of a data analysis process?
Checking for changes (usally in a security context).
import hashlib # Can take a 'salt' (similar to a 'seed')
r1 = hashlib.md5('CASA Intro to Programming'.encode())
print(f"The hashed equivalent of r1 is: {r1.hexdigest()}")
r2 = hashlib.md5('CASA Intro to Programming '.encode())
print(f"The hashed equivalent of r2 is: {r2.hexdigest()}")
r3 = hashlib.md5('CASA Intro to Programming'.encode())
print(f"The hashed equivalent of r3 is: {r3.hexdigest()}")
Outputs:
import requests
night = requests.get("http://www.gutenberg.org/ebooks/1514.txt.utf-8")
print(f"The text is {night.text[30:70]}")
print(f"The text is {len(night.text):,} characters long")
hash = hashlib.md5(night.text.encode())
print(f"This can be hashed into: {hash.hexdigest()}")
Outputs:
You may have noticed this in Docker:
How this was generated:
import uuid, hashlib
salt = uuid.uuid4().hex[:16] # Truncate salt
password = 'casa2021' # Set password
# Here we combine the password and salt to
# 'add complexity' to the hash
hashed_password = hashlib.sha1(password.encode() +
salt.encode()).hexdigest()
print(':'.join(['sha1',salt,hashed_password]))
Simple hashing algorithms are not normally secure enough for full encryption. Genuine security training takes a whole degree + years of experience.
Areas to look at if you get involved in applications:
Randomness • Jon Reades