This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = '' |