def main(): # basic encryption example #a = 9 #b = 7 #n = 143 # basic decryption example #a = 48 #b = 103 #n = 143 a = 1094051021 b = 65537 n = 3322225339 # online example https://www.cs.utexas.edu/~mitra/honors/soln.html #a = 2 #b = 7 #n = 33 # new example # a = 2 # encrypt # b = 7 # a = 29 # decrypt # b = 3 # n = 33 ## massive example # encrypt # a = 1976620216402300889624482718775150 # b = 65537 # decrypt # a = 35052111338673026690212423937053328511880760811579981620642802346685810623109850235943049080973386241113784040794704193978215378499765413083646438784740952306932534945195080183861574225226218879827232453912820596886440377536082465681750074417459151485407445862511023472235560823053497791518928820272257787786 # b = 89489425009274444368228545921773093919669586065884257445497854456487674839629818390934941973262879616797970608917283679875499331574161113854088813275488110588247193077582527278437906504015680623423550067240042466665654232383502922215493623289472138866445818789127946123407807725702626644091036502372545139713 # n = 145906768007583323230186939349070635292401872375357164399581871019873438799005358938369571402670149802121818086292467422828157022922076746906543401224889672472407926969987100581290103199317858753663710862357656510507883714297115637342788911463535102712032765166518411726859837988672111837205085526346618740053 # n = 1003376531 # #test # a = 55 # b = 65537 #n = 555427658531 #a = 365122258834 #b = 126513109889 print("result: " + str(common.mod_exp(a, b, n)))
def createTestStringME(base, exp, mod, bits): base_b = binaryString(base, bits) exp_b = binaryString(exp, bits) mod_b = binaryString(mod, bits) wait_time = waitTime(bits, modular_exponentiation) m_res = common.mod_exp(base, exp, mod) m_res_b = binaryString(m_res, bits) return ("\tREPORT \"Begin test case for base=%(base)d, exp=%(exp)d, mod=%(mod)d\";\n" "\tREPORT \"Expected output is %(m_res)d, %(m_res_b)s\";\n" "\tN_in <= \"%(base_b)s\";\n" "\tExp_in <= \"%(exp_b)s\";\n" "\tM_in <= \"%(mod_b)s\";\n" "\twait for %(wait_time)d * clk_period;\n" "\tASSERT(C_out = \"%(m_res_b)s\") REPORT \"test failed\" SEVERITY NOTE;\n\n" % locals())