<jupyter_start><jupyter_text>$$public-key: matrix \quad A \in \mathbb{Z}_{q}^{n \times m}$$$$secret-key: s=(1|s′) \in \mathbb{Z}_{q}$$$$ \textrm{KeyGeneration() -> A, s}$$$$ \textrm{Choose} \quad s′ \in_R \mathbb{Z}^{n−1}_{q} \quad \textrm{and write} \quad  s = (1 | s')$$$$ \textrm{Choose} \quad e \leftarrow \chi^m $$$$ \textrm{Choose} \quad A' \in \mathbb{Z}_q^{{(n-1)}\times m}$$. $$ \textrm{Compute} \quad b = e-(s')^TA'.$$$$ \textrm{Set} \quad A = \textrm{matrix where b is the first row and the rest of the rows} =A'$$$$ A = \left(\begin{array}{cc}-b-\\ A' \end{array}\right)$$$$\textrm{Enc}(\sigma \in \mathbb{Z}_p)\quad \textrm{where} \quad p\quad < q$$$$r \leftarrow \chi^m$$$$c = [Ar+(\lfloor \sigma \cdot q/p \rfloor)(1,0,0,...,0)]_q$$$$\textrm{Dec}(c,s):$$$$\textrm{Inner product of} \quad v=[\langle s, c \rangle]_q$$$$\textrm{Compute} \quad \lfloor v \times p/q \rfloor$$$$s^TAr + \lfloor \sigma \cdot q/p \rfloor$$$$s^TAr = (1|s')^T\left(\begin{array}{cc}-b-\\ A' \end{array}\right)r = (b+(s')^TA')r = (e^T - (s'^T)A'+((s'^T)A')r = e^Tr$$<jupyter_code>import ligero
import math
import numpy as np
from pprint import pprint
import random

ChiSTD = 3.2 * 4
SecretMessageSigma = 1

q = 1340780792994259709957402499820584612747936582059239337772356144372176403007354697680187429816690342769003185818648605085375388281194656994643364900
print("q = ", q)
p = 340282366920938463463374607431768211455
print("p = ", p)

n = 2
m = 2
def generateKeys():
    sprime = []
    sprime.append(1)
    for _ in range(n):
      sprime.append(random.getrandbits(128) % q)
    s = np.array(sprime)
    eprime = []
    
    for _ in range(m):
      eprime.append(0)
    e = np.array(eprime)
    return {"s":s, "A":A}
    
    
keys = generateKeys()
print(keys)




def Enc(sigma):
    r = np.array([-4, 2, -2])
    print("r = ", r, "\n")
    cprime = np.array([
        29328288400520622882860467459894979154131035150580408025009084735645322255682920810692681865114430890494535604910055051260752775951034689835943017435762017
       ,30
       ,-29328288400520622882860467459894979154091633144384013545796805695545178641877725279332979102251059026105281195230704230382305948193646853236521044547603826
       ,31
       ,-40740742453138361403133355882170855090191458014215486301963788896311854393584685039583922605385579431390449945150722695149160700984214549790186134204421536
    ])
    print("cprime = ", cprime, "\n")
    c = np.array([
2512672540635428683712417463483286899172303509395621269561961848201794195535826857088933268780624035114471888537082949553245010327141549943075719423593827
,-2512672540635428683712417463483286899132901503199226790349682808101650581730631325729230505917252170725217478857732128674798182569753713343653746535435636
,-517318663310570104411280887553316707753360552438306168793104565146562303364044109178299710884869148320354370591264542587899052548374839950885187186169251 
    ])
    return c

print("Sigma = ", SecretMessageSigma, "\n")
encryptedMessage = Enc(SecretMessageSigma)
print("c = ", encryptedMessage, "\n")
pprint(encryptedMessage.tolist(), indent=2)


#    Inner product of v=[⟨s,c⟩]q: 39402006196394479212279040100143613805195531359702762863371864389254409679350820878446827757387836599421972888158191
def Dec(c, s):
    vprime = np.dot(s, c)
    v = vprime % q
    print("v = ", v)
    dprime = (v * p) / q
    print("dprime = ", dprime)

decryptedMessage = Dec(encryptedMessage, secretKey)<jupyter_output>Sigma =  1 

r =  [-4  2 -2] 

cprime =  [29328288400520622882860467459894979154131035150580408025009084735645322255682920810692681865114430890494535604910055051260752775951034689835943017435762017
 30
 -29328288400520622882860467459894979154091633144384013545796805695545178641877725279332979102251059026105281195230704230382305948193646853236521044547603826
 31
 -40740742453138361403133355882170855090191458014215486301963788896311854393584685039583922605385579431390449945150722695149160700984214549790186134204421536] 

c =  [2512672540635428683712417463483286899172303509395621269561961848201794195535826857088933268780624035114471888537082949553245010327141549943075719423593827
 -2512672540635428683712417463483286899132901503199226790349682808101650581730631325729230505917252170725217478857732128674798182569753713343653746535435636
 -517318663310570104411280887553316707753360552438306168793104565146562303364044109178299710884869148320354370591264542587899052548374839950885187186169251] [...]
{'fraction_non_alphanumeric': 0.12138209557998654, 'fraction_numerical': 0.49158626879066636, 'mean_word_length': 6.47986577181208, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '282145', 'license': 'Apache-2.0', 'n_tokens_mistral': 3142, 'n_tokens_neox': 1875, 'n_words': 230, 'path': 'doc/notebooks/EncryptionScheme.ipynb', 'repo_name': 'JustinDrake/LigeroRSA', 'size': '4457'}