Skip to content

Commit

Permalink
Create lynx_cybersecurity.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jul 28, 2024
1 parent d3cdb99 commit b6710ef
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import hashlib
import hmac
import os
import secrets
from cryptography.fernet import Fernet

class Cybersecurity:
def __init__(self, secret_key):
self.secret_key = secret_key

def encrypt(self, data):
encrypted_data = hmac.new(self.secret_key.encode(), data.encode(), hashlib.sha256).hexdigest()
return encrypted_data

def decrypt(self, encrypted_data):
# Note: HMAC is a one-way hash function, it's not possible to decrypt the data.
# This method is just a placeholder and will not work as expected.
return encrypted_data

def generate_key(self):
key = Fernet.generate_key()
return key

def symmetric_encrypt(self, data, key):
cipher_suite = Fernet(key)
encrypted_data = cipher_suite.encrypt(data.encode())
return encrypted_data

def symmetric_decrypt(self, encrypted_data, key):
cipher_suite = Fernet(key)
decrypted_data = cipher_suite.decrypt(encrypted_data)
return decrypted_data.decode()

def hash_data(self, data):
hashed_data = hashlib.sha256(data.encode()).hexdigest()
return hashed_data

def verify_signature(self, data, signature):
expected_signature = hmac.new(self.secret_key.encode(), data.encode(), hashlib.sha256).hexdigest()
return hmac.compare_digest(signature, expected_signature)

# Example usage:
secret_key = secrets.token_bytes(32)
cybersecurity = Cybersecurity(secret_key)

data = "Hello, World!"
encrypted_data = cybersecurity.encrypt(data)
print(f"Encrypted data: {encrypted_data}")

key = cybersecurity.generate_key()
print(f"Generated key: {key}")

symmetric_encrypted_data = cybersecurity.symmetric_encrypt(data, key)
print(f"Symmetric encrypted data: {symmetric_encrypted_data}")

symmetric_decrypted_data = cybersecurity.symmetric_decrypt(symmetric_encrypted_data, key)
print(f"Symmetric decrypted data: {symmetric_decrypted_data}")

hashed_data = cybersecurity.hash_data(data)
print(f"Hashed data: {hashed_data}")

signature = hmac.new(secret_key, data.encode(), hashlib.sha256).hexdigest()
is_signature_valid = cybersecurity.verify_signature(data, signature)
print(f"Is signature valid? {is_signature_valid}")

0 comments on commit b6710ef

Please sign in to comment.