Skip to content

Instantly share code, notes, and snippets.

View adil9004's full-sized avatar

adil ansari adil9004

  • mira bhayandar
  • 08:47 (UTC -12:00)
View GitHub Profile
def generate_primes(n):
primes = []
num = 2
while len(primes) < n:
if all(num % p != 0 for p in primes):
primes.append(num)
num += 1
return primes
def fractional_part(root, is_cube=False):
1]without using halib
import math
K = [int((1 << 32) * abs(math.sin(i + 1))) & 0xFFFFFFFF for i in range(64)]
S = [
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
]
@adil9004
adil9004 / gist:30eef1890da785a6fe6139708cec8a21
Created October 13, 2025 11:39
Diffie-Hellman Key Exchange
import random
def is_prime(n):
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
@adil9004
adil9004 / gist:3ea97b7a3ed13a963dc6d9fab2c751d8
Created October 13, 2025 09:42
RSA Encryption and Decryption
import random
def is_prime(n):
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def generate_prime(min_value, max_value):
prime = random.randint(min_value, max_value)
def caesar_encrypt(text, shift):
encrypted = ""
for char in text:
if char.isalpha():
ascii_base = ord('A') if char.isupper() else ord('a')
shifted = (ord(char) - ascii_base + shift) % 26 + ascii_base
encrypted += chr(shifted)
else:
encrypted += char
return encrypted
@adil9004
adil9004 / gist:cfbcf352a37cbf0050fb40230d0279d5
Last active October 13, 2025 09:24
Rail Fence Encryption
def rail_fence_encrypt(text, rails):
fence = ['' for _ in range(rails)]
rail = 0
direction = 1
for char in text.replace(" ", ""):
fence[rail] += char
if rail == 0:
direction = 1
elif rail == rails - 1:
direction = -1
@adil9004
adil9004 / gist:9885c82fa7bacb1d0f3163b2dea8d195
Last active October 13, 2025 09:05
Columnar Transposition
def columnar_encrypt(plaintext, key):
plaintext = plaintext.replace(' ', '').upper()
key = key.upper()
n_cols = len(key)
n_rows = (len(plaintext) + n_cols - 1) // n_cols
padded_length = n_rows * n_cols
padded_text = plaintext.ljust(padded_length, 'X')
matrix = [list(padded_text[i * n_cols:(i + 1) * n_cols]) for i in range(n_rows)]
order = sorted(range(n_cols), key=lambda k: key[k])
ciphertext = ''