Skip to content

gowthamch54/CC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1. Checksum Calculation

data_blocks = ['11010101', '01100011', '11110000'] total = 0 for block in data_blocks: total += int(block, 2) while total > 255: total = (total & 0xFF) + (total >> 8) checksum = ~total & 0xFF print("Checksum:", format(checksum, '08b'))

2. Cyclic Redundancy Check (CRC)

dataword = '100100' divisor = '1101' padded = dataword + '0' * (len(divisor)-1) temp = padded[:len(divisor)] result = '' for i in range(len(dataword)): if temp[0] == '1': for j in range(1, len(divisor)): result += str(int(temp[j]) ^ int(divisor[j])) else: for j in range(1, len(divisor)): result += str(int(temp[j]) ^ 0) temp = result + padded[len(divisor)+i] result = '' codeword = dataword + temp print("CRC Codeword:", codeword)

3. Character Stuffing

data = "Hello$World@Test" stuffed = "" for char in data: if char == '$' or char == '@': stuffed += "\" + char else: stuffed += char print("Stuffed Data:", stuffed)

4. Bit Stuffing

data = "1111101111110" stuffed = "" count = 0 for bit in data: stuffed += bit if bit == '1': count += 1 if count == 5: stuffed += '0' count = 0 else: count = 0 print("Stuffed Bits:", stuffed)

5. Subnet Mask Calculation

prefix = 24 mask_bits = '1'prefix + '0'(32 - prefix) subnet_mask = '' for i in range(0, 32, 8): block = mask_bits[i:i+8] subnet_mask += str(int(block, 2)) + '.' subnet_mask = subnet_mask[:-1] print("Subnet Mask:", subnet_mask)

6. RSA Encryption

msg = "HI" e = 17 n = 3233 encrypted = [] for char in msg: encrypted.append(pow(ord(char), e, n)) print("RSA Encrypted:", encrypted)

7. Diffie-Hellman Key Exchange

g = 5 p = 23 a = 6 b = 15 A = pow(g, a, p) B = pow(g, b, p) shared_key = pow(B, a, p) print("Shared Key:", shared_key)

8. Symmetric Key Encryption (Caesar Cipher)

text = "HELLO" key = 3 cipher = "" for char in text: cipher += chr((ord(char) - 65 + key) % 26 + 65) print("Caesar Encrypted:", cipher)

9. Monoalphabetic Substitution Cipher

text = "HELLO" key = "QWERTYUIOPASDFGHJKLZXCVBNM" cipher = "" for char in text: cipher += key[ord(char) - 65] print("Mono Encrypted:", cipher)

10. Polyalphabetic Substitution Cipher (Vigenère)

text = "HELLO" key = "KEY" cipher = "" for i in range(len(text)): t = ord(text[i]) - 65 k = ord(key[i % len(key)]) - 65 cipher += chr((t + k) % 26 + 65) print("Vigenère Encrypted:", cipher)

11. Hill Cipher (2x2 Matrix)

import numpy as np text = "HI" vec = [[ord(text[0])-65], [ord(text[1])-65]] key = np.array([[3, 3], [2, 5]]) result = np.dot(key, vec) % 26 cipher = '' for val in result: cipher += chr(int(val[0]) + 65) print("Hill Encrypted:", cipher)

12. Playfair Cipher Grid Setup

key = "MONARCHY" key = key.upper().replace('J', 'I') grid = "" used = [] for c in key + 'ABCDEFGHIKLMNOPQRSTUVWXYZ': if c not in used: grid += c used.append(c) for i in range(0, 25, 5): print(grid[i:i+5])

13. DES Encryption (Simulation)

from Crypto.Cipher import DES msg = "HELLO123" key = "12345678" cipher = DES.new(key.encode(), DES.MODE_ECB) encrypted = cipher.encrypt(msg.encode()) print("DES Encrypted:", encrypted)

14. AES Encryption (Simulation)

from Crypto.Cipher import AES msg = "HELLO JAVA" key = "abcdefghijklmnop" cipher = AES.new(key.encode(), AES.MODE_ECB) encrypted = cipher.encrypt(msg.ljust(16).encode()) print("AES Encrypted:", encrypted)

15. MD5 Hashing

import hashlib text = "Java" hashed = hashlib.md5(text.encode()).hexdigest() print("MD5 Hash:", hashed)

16. SHA-256 Hashing

import hashlib text = "Java" hashed = hashlib.sha256(text.encode()).hexdigest() print("SHA-256 Hash:", hashed)

17. Digital Signature Generation and Verification

msg = "data" priv_key = 53 n = 3233 signature = pow(hash(msg), priv_key, n) print("Digital Signature:", signature)

18. IP Spoofing Simulation

print("Sending packet with fake IP: 192.168.0.100")

19. TCP Packet Sniffing (Basic)

import socket s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP) packet, addr = s.recvfrom(65565) print("Received Packet:", packet)

20. Client-Server Socket Programming

Server (Run separately)

import socket

s = socket.socket()

s.bind(('',9999))

s.listen(1)

conn, addr = s.accept()

print(conn.recv(1024))

Client (Run separately)

import socket

s = socket.socket()

s.connect(('localhost',9999))

s.send(b"Hello from Client")

21. Firewall Rule Simulation

rules = ["blocked.com", "malicious.com"] packet = "good.com" if packet in rules: print("Packet Blocked") else: print("Packet Allowed")

22. DNS Spoofing Demonstration

domain = "example.com" print(domain, "resolved to fake IP: 10.0.0.99")

23. ARP Spoofing Demonstration

print("Sent fake ARP reply claiming to be gateway at 192.168.1.1")

24. Steganography – Hide Character in Image

from PIL import Image img = Image.open("input.png") img.putpixel((0,0), (ord('H'), 0, 0)) img.save("hidden.png") print("Character hidden in image.")

25. Secure Multi-cloud Data Sharing using Homomorphic Encryption & Blockchain

data = "sensitive_info" encrypted = "Encrypted(" + data + ")" blockchain_verified = encrypted + " + Blockchain Verified" print("Secure Share:", blockchain_verified)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published