<jupyter_start><jupyter_text>Compute Greatest Common Divisor<jupyter_code>def remainder(a,b):
    return a%b

def gcd(a,b):
    r=remainder(a,b)
    if r==0:
        return b
    return gcd(b,r)

print(gcd(300,100))
print(gcd(121,11))
print(gcd(7,3))<jupyter_output>100
11
1<jupyter_text>Efficiently determining if a number is a divisor<jupyter_code>def divisible(a,d):
    n_integers=len(str(a))
    if d<=n_integers:
        a=a%d
        base=10%d
        if a==0:
            return True
    n_integers=len(str(a))
    partial_sum=0
    for n in range(n_integers):
        partial_sum+=(int(str(a)[n])*10)%d
    if partial_sum==0:
        return True
    else:
        return False
        
    
div=divisible(30332,3)
print(div)
div=divisible(400044,4)
print(div)
div=divisible(25000055,5)
print(div)<jupyter_output>False
True
True<jupyter_text>Caesar Cipher<jupyter_code>import string
def caesar_cipher(shift,plain_text):
    alphabet=np.array(list(string.ascii_lowercase))
    print(alphabet)
    shifted_alphabet=np.roll(alphabet,shift)
    print(shifted_alphabet)
    mapping={}
    for letter in range(0,26):
        mapping[alphabet[letter]]=shifted_alphabet[letter]
    encrypted_text=''
    for letter in plain_text:
        encrypted_text+=mapping[letter]
    return encrypted_text
        

encrypted_text=caesar_cipher(-28,'meetmelater')
print(encrypted_text)

def caesar_cipher_decrypt(shift,cipher_text):
    alphabet=np.array(list(string.ascii_lowercase))
    #print(alphabet)
    shifted_alphabet=np.roll(alphabet,shift)
    #print(shifted_alphabet)
    mapping={}
    for letter in range(0,26):
        mapping[shifted_alphabet[letter]]=alphabet[letter]
    plain_text=''
    for letter in cipher_text:
        plain_text+=mapping[letter]
    return plain_text


plain_text=caesar_cipher_decrypt(-5,'QNGWFWD'.lower())
print(plain_text)
26%3<jupyter_output><empty_output><jupyter_text>Monoalphabetic cipher<jupyter_code>def monoalphabetic_decrypt(permuted_alphabet,cipher_text):
    alphabet=np.array(list(string.ascii_lowercase))
    mapping={}
    for letter in range(0,26):
        mapping[permuted_alphabet[letter]]=alphabet[letter]
    plaintext=''
    for letter in cipher_text:
        plaintext+=mapping[letter]
    return plaintext

plaintext=monoalphabetic_decrypt('DKVQFIBJWPESCXHTMYAUOLRGZN','AOVVFAA')
print(plaintext)<jupyter_output>success<jupyter_text>Vigenere cipher<jupyter_code>import string

def repeat_to_length(string_to_expand, length):
    return (string_to_expand * (int(length/len(string_to_expand))+1))[:length]

def convert_alphabet_to_numeric(alphabet):
    numeric_mapping={}
    rng=range(26)
    for ind in range(len(alphabet)):
        numeric_mapping[alphabet[ind]]=rng[ind]
    return numeric_mapping

def inverse_numeric_mapping(alphabet):
    numeric_mapping={}
    rng=range(26)
    for ind in range(len(alphabet)):
        numeric_mapping[rng[ind]]=alphabet[ind]
    return numeric_mapping 

def vigenere_decrypt(key,cipher_text):
    alphabet=list(string.ascii_lowercase)
    map_orig_alphabet=convert_alphabet_to_numeric(alphabet)
    print(map_orig_alphabet)
    #map_key=convert_alphabet_to_numeric(key)
    expanded_key=repeat_to_length(key,len(cipher_text))
    inverse_numeric_mapping_=inverse_numeric_mapping(alphabet)
    plain_text=''
    print(expanded_key)
    print(inverse_numeric_mapping_)
    for ind in range(len(cipher_text)):
        orig_numeric=map_orig_alphabet[cipher_text[ind]]
        key_numeric=map_orig_alphabet[expanded_key[ind]]
        print(cipher_text[ind],expanded_key[ind],orig_numeric,key_numeric)
        decrypted_numeric=(orig_numeric-key_numeric)%26
        decrypted_bletter=inverse_numeric_mapping_[decrypted_numeric]
        plain_text+=decrypted_letter
    return plain_text

plain_text=vigenere_decrypt('LEMON'.lower(),'DTXSAOMP'.lower())
print(plain_text.upper())

def vigenere_encrypt(key,plain_text):
    alphabet=list(string.ascii_lowercase)
    map_orig_alphabet=convert_alphabet_to_numeric(alphabet)
    #print(map_orig_alphabet)
    #map_key=convert_alphabet_to_numeric(key)
    expanded_key=repeat_to_length(key,len(plain_text))
    inverse_numeric_mapping_=inverse_numeric_mapping(alphabet)
    cipher_text=''
    for ind in range(len(plain_text)):
        pt_numeric=map_orig_alphabet[plain_text[ind]]
        key_numeric=map_orig_alphabet[expanded_key[ind]]
        encrypted_numeric=(pt_numeric+key_numeric)%26
        encrypted_letter=inverse_numeric_mapping_[encrypted_numeric]
        cipher_text+=encrypted_letter
        print(encrypted_letter)
    return cipher_text

cipher_text=vigenere_encrypt('XO'.lower(),'DRAGON'.lower())
print(cipher_text.upper())
st=vigenere_decrypt('XO'.lower(),'RGZNFIBJWPESCXHTMYAUOLDKVQ'.lower())
print(st)<jupyter_output>{'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
xoxoxoxoxoxoxoxoxoxoxoxoxo
{0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j', 10: 'k', 11: 'l', 12: 'm', 13: 'n', 14: 'o', 15: 'p', 16: 'q', 17: 'r', 18: 's', 19: 't', 20: 'u', 21: 'v', 22: 'w', 23: 'x', 24: 'y', 25: 'z'}
r x 17 23
g o 6 14
z x 25 23
n o 13 14
f x 5 23
i o 8 14
b x 1 23
j o 9 14
w x 22 23
p o 15 14
e x 4 23
s o 18 14
c x 2 23
x o 23 14
h x 7 23
t o 19 14
m x 12 23
y o 24 14
a x 0 23
u o 20 14
o x 14 23
l o 11 14
d x 3 23
k o 10 14
v x 21 23
q o 16 14
uscziuevzbhefjkfpkdgrxgwyc
{'fraction_non_alphanumeric': 0.13192182410423453, 'fraction_numerical': 0.04542164314151285, 'mean_word_length': 4.751300728407909, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 6}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '288000', 'license': 'MIT', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2141, 'n_words': 415, 'path': 'CryptoMath.ipynb', 'repo_name': 'mariakesa/QuantumCryptography', 'size': '5526'}