vinnik-dmitry07 / cryptography

The basic algorithms of cryptography

Home Page:https://wandbox.org/permlink/MXMZgvOdMboYse7R

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cryptography

Long integer arithmetic is implemented:

  1. Operations: addition, subtraction, multiplication, division with the remainder, raising to a natural degree
  2. Comparison of numbers (<,>, =)
  3. The same operations (except comparison) for a given module
  4. Finding [√x], where [x] denotes an integer part x ∈ Z
  5. Solving first-order comparison systems • The digit number is not limited to a predefined program the upper border.

Using the module of long arithmetic, the basic algorithms of cryptography and number theory are implemented:

  1. Pollard's Po-algorithm for factorizing long integers
  2. Algorithm "Baby-step giant-step" finding a discrete logarithm
  3. Calculation of Euler and Möbius functions
  4. Calculation of Legendre and Jacobi symbols
  5. Chippole's algorithm for finding a discrete square root
  6. Miller–Rabin primality test
  7. El-Gamal cryptosystem.

Output

ElGamal cryptosystem:
	Original message: 	Hello there!
g^k used : 11701555583593688132103794749619549272680851959481
g^ak used : 34518093716079085119431604859116382522833135703669
	Decripted message: 	Hello there!
24523748428⁶⁵⁰⁰⁰⁰⁰ (mod 98723459723):
	3007310280
123456789876543212345678987654321 * 159753579515975357951:
	19722664098329407668409980551455712567936587826856271
sqrt(9⁴⁰):
	12157665459056928801
9²⁰:
	12157665459056928801
10²⁰ + 1 > 10²⁰:
	true
1234567^1234:
	84936719337595738025354100892018527324915025840012534055559738926388960395898693736072171172232172368493162402373753103670585103318337561430645247757736982191857981348566917727981105337093396972115082336451061319384673060435875994765812925152527021230884195534655127460724921754816391298005120782512470911443492346801619496384537586728750520409651598692379297026867662598796289391626149462643510163687922723985519275829471393791192155053131060518954897241226250658949131606954874144084013759753301522329514799290307918889450342882487511713479272046661942966613412761543023028379796999202108924067772142723274002880268131855205160840388473538134833916877480536240517787827418354230677995790223780484899379885890613556688891308360191761967408717373761702017241261682915574767639299832573010650901237119231586334530059007286138229811683534453232494824521347892133297058048150589437225314186760066840850145778668317808284575743755042827974946022124066578091683003327560980258183090447764039675040364693938573699739776102620362885279347248867496969687632170224851608540274019114855151230061322241509499596545187468689309758043357019370647539517397286652093937022641838140886590189709482131680585519603697627744011574915343734780986679628486129354388233620456090036735057647994691760241970018653561034713928887410719314473736507590985982213315547479125139168262740259382245903857506327850838646065307983620369174625587857950271358715639561718955769327032569108796037316037897642058441610257403871081404913788053794096123974885552983304981654963383937182912618205773399088160118959046546010762916885400535412040721471532257952593542784117776581878693451875313816747076246324710954328582746893958672730334428844986062688654186489712370830046451985511534682182435235049811927549778593414882782167050223884736574345365289488121249301988402215691602344561716191504175814116124013360352209429907967029944667240127780265456674259505995672064781327680427419205275694368628720291452868917639820938160406318056630280322762414404415435407240673839247979121992990334953490747813619869032877915924280727904231071509375036544600948525981884579683463399426950602893894745528373126732957937576116660954412176289061048762619711240262631366347818154856847834921908042232709831150661363002776958550985148231428664543769316838239390601483638593030192924071110395260191302948980969632005986337532197267266003556131905160440325609071301356075564752777085339765640370086132249023571505345329257100394231604009660966890069047884045450828311633473834056171005275121662468119042624414992739901730914769617166669011095575530030350287584074645201579315773401251688949171152478292386941145548813858409944476879095137320343164418346705436642604815773138014818471426757479958581425644882228208441715304210297826743997773892453258442125631646191109824758505294601873460310102594703671299582655444277414991184234847446050562912755573210562658008289778236174012059495090034148571803140778841129389116623451398563707936415324415827401509366427554579975943327222919298519336026378022100035639827456731303368686409606908627079935716603520994997815229361153660212433631450002014281541874999275112019290582013725805505948865981880337951929659476911579719751572887655467925342397363134610922414716261346440525220582275605808334925488654376599022481943945004702116702477433669395895457967660337280926281271839633659373202148944326364155864890407914763960912896383116887526305307980976588536970651044849478741425098326946392224002986632176473941584025911966439294666026791503690839243078563698545351105124635810023698168704466742640473696730791919849605996519855150796539477074462233228449215614061908258672461886290579537501090543891561311108755591319436198496373874056344602446608215955825059605133408723242540498375448562906364537119468519303632622808653217307494693956453778722160419319065911689182926772344170047126606181276797617854512167879405815699710705051373495148045160355666981570530490210401918414544018970446083992404836596370226644666563617920261216509508248145385664033282945432716504608991495416098547550591572749993205179017600281732452747255266787036173928778532351302155229388636860534677552851923013415201030095931811120908909652132835367030439567027081332065686916338596114501019394006877558326390893324807372134134593147923452590929129158805987990184818622265971266255935010481864518293472486004375422970934210558378852602176687121412252744574646721153250686502083521855908348387619159314327001553043435120898396023325660979601928949378607135695792414171687069322630483959078426351173105938078889161032086610878155411900828426323499830080822798389822827864162504542163569491767648956236814385791490323507900362720086553101512766895775718689402745158664640141289044862188713666309101661947601791280557766021352227546988177380057135687457375686075664747238875181983682370735129805614556230331089353303481343217340285443485802642182883775164042964326619989464390166107612335501268808639875946839784676079225624455281670441271485475145076004857850847694130676698918657822099680499391460964501889833575422050320586501689595967803170095222839742979101491149566617721917475443321737126450557928658690864432911090912964641441505559496312546657226600144081501949152746755750940626780947665208333003196278928780730745380591652371402336658509868582981779244247631953511287266816028084272569122052777527271099139201886220593532692503483074525594856418318121361736142334368576686431654408335446753575775490844015046299775025399373982549806738154835868561260000497797988754498606015160132827591575260013850829854398460158391008426141550103264449879739477877676432969993844290837991862641665934790927191760620555844937134195960968042743009620340549587794957169882197063903453402591056055834787276073292233745101605946596292588264660261802345507373027715319804481317089786680893503823941588634579444072210203697662341363684992553265996209566931022314087136698352730497176941203218126169654376222414456459281097318235647046513629649180531203440488066453954784047440981515039170804703152343031228057771107787505646898597486124022478263568408170502756103720682671990302723301187222542254434853937910094163519362998422011426252197212507344011239755221647776055424983669708426126839232978819852166855653226108051060857195625054367751160071429232874845766398358828870179655477437198908760794812365209070779508200544501584834139388975235520853712766654245906888051315089817614231278799345874379159361025834893074452117738916140668790686959990860984388454409514729118250208174669171718198933379393492618906841822393099031443678146010522802534595721151658600131245963726684943290106949695137301898380464644157215591045932921739453158694645214811097578450662306285797902970244639552164577260901756301918029742061069214954906076183110548505330364358033163698707893888956222324005833057911505575616285051698253679545142614956445063099869491677317541255766116478870096848884739755165141800401885664982541916911966286967053299127617437154218357561994978520977719450549229819015008748857507610553905436538084530021991666672176903600817685486996960272982705270808046499765876456364365397440233697376841063303101751998666555009878635770169519572846491175484875132336612512990499862584607864070427386926072469595804037389080638844144674138750254622184718733498830378767096228079180636886632290504997295208762918145853266917006410294144265305466270854106261490693772550894412824900869504109367335040806335167055437716316564402501839239573180431145079892450232497271801754327729
Factorization of 17348256187264213649126346457:
	29 16451 36363487362185746279183 
x³ ≡ 1  (mod 196134577):
	24516822
totient(1000):
	400
mobius(1234891):
	1
legendre1(30, 109):
	108
jacobi(1001, 9907):
	-1
x² ≡ 34035243914635549601583369544560650254325084643201 (mod 10⁵⁰ + 151):
	82563118828090362261378993957450213573687113690751 17436881171909637738621006042549786426312886309400
x ≡ 16 (mod 17)
x ≡ 22 (mod 23)
x ≡ 30 (mod 31)
	12120