INSPRAC
INSPRAC
if decrypt:
shift = -shift
upper_case = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lower_case = 'abcdefghijklmnopqrstuvwxyz'
return text.translate(table)
if __name__ == "__main__":
encrypted = caesar_cipher(plaintext)
print("YOUR NAME")
if decrypt:
shift = -shift
upper_case = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lower_case = 'abcdefghijklmnopqrstuvwxyz'
return text.translate(table)
if __name__ == "__main__":
print("YOUR NAME")
row, step = 0, 1
rail[row] += char
row += step
return ''.join(rail)
for i in range(len(cipher)):
rail[row][i] = '*'
row += step
for r in range(key):
for c in range(len(cipher)):
for i in range(len(cipher)):
result.append(rail[row][i])
row += step
return ''.join(result)
message = "HELLOWORLD"
key = 2
print("YOUR NAME")
cols = len(key)
index = 0
for i in sorted_key_indices:
if __name__ == "__main__":
print("YOUR NAME")
2 Diffie helman
def power(a, b, p):
return pow(a, b, p)
def main():
P, G = 23, 10
a, b = 4, 3
print(f"Secret key for Party 1: {ka}, Secret key for Party 2: {kb}")
if __name__ == "__main__":
main()
print("YOUR NAME")
3.DES
from Crypto.Cipher import DES
import os
iv = cipher.iv
encrypted = cipher.encrypt(text.ljust(16).encode())
if __name__ == "__main__":
key = os.urandom(8)
print("Encrypted:", encrypted.hex())
print("Decrypted:", decrypted)
print("YOUR NAME")
4.RSA
import random
import random
while b: a, b = b, a % b
return a
if (e * d) % phi == 1: return d
n=p*q
phi = (p - 1) * (q - 1)
e = random.randrange(1, phi)
e, n = public_key
return [pow(ord(c), e, n) for c in plaintext]
d, n = private_key
if __name__ == "__main__":
p, q = 61, 53
print("Encrypted:", encrypted)
print("Decrypted:", decrypted)
print("YOUR NAME")
5.MESSAGE DIGEST 5
from cryptography.hazmat.primitives.asymmetric import dsa
if not msg:
else:
print("YOUR NAME")
6.DIGITAL SIGNATURE
if not msg:
else:
print(f"Signature: {sig.hex()}")
print("YOUR NAME")
7.MAC
import os
def generate_key():
hmac.update(message.encode())
return hmac.finalize()
if __name__ == "__main__":
print("-MAC-")
key = generate_key()
if not message:
else:
print(f"HMAC: {hmac.hex()}")
try:
hmac_verifier.update(message.encode())
hmac_verifier.verify(hmac_to_verify)
print("HMAC is valid.")
except Exception:
print("HMAC is invalid.")
print("YOUR NAME")
8.MALWARE
import hashlib
import os
KNOWN_MALWARE_HASHES = {
'e99a18c428cb38d5f260853678922e03',
'5e884898da28047151d0e56f8dc62927'
hash_func = hashlib.new(hash_algo)
hash_func.update(chunk)
return hash_func.hexdigest()
def scan_file(file_path):
file_hash = compute_file_hash(file_path)
if file_hash in KNOWN_MALWARE_HASHES:
return True
return False
def scan_directory(directory):
scan_file(os.path.join(root, file))
def main():
if not os.path.isdir(directory):
print("Invalid directory.")
return
scan_directory(directory)
print("Scan completed.")
if __name__ == "__main__":
print("\t-Malware Antivirus-")
main()
print("your name")