Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
RSA Encyption example with large numbers using System.Numerics.BigInteger
' RSA Encyption example with large numbers using System.Numerics.BigInteger Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Text.RegularExpressions Imports System.Numerics Imports Microsoft.VisualBasic Namespace Rextester Public Module Program Dim n as biginteger = biginteger.parse("145906768007583323230186939349070635292401872375357164399581871019873438799005358938369571402670149802121818086292467422828157022922076746906543401224889672472407926969987100581290103199317858753663710862357656510507883714297115637342788911463535102712032765166518411726859837988672111837205085526346618740053") Dim e as biginteger = biginteger.parse("65537") Dim d as biginteger = biginteger.parse("89489425009274444368228545921773093919669586065884257445497854456487674839629818390934941973262879616797970608917283679875499331574161113854088813275488110588247193077582527278437906504015680623423550067240042466665654232383502922215493623289472138866445818789127946123407807725702626644091036502372545139713") Public Sub Main(args() As string) ' Public key is (e,n) ' Private key = (d,n)) Dim plainText1before as biginteger = biginteger.parse("1976620216402300889624482718775150") Dim plainText2before as biginteger = biginteger.parse("7268237837345551102925775245561192465854311") Dim cipherText1 as biginteger = Encrypt(plainText1before) Dim cipherText2 as biginteger = Encrypt(plainText2before) Dim plainText1after as biginteger = Decrypt(cipherText1) Dim plainText2after as biginteger = Decrypt(cipherText2) Console.WriteLine("plainText1 before encryption = " & plainText1before.ToString() & vbcrlf) Console.WriteLine("plainText2 before encryption = " & plainText2before.ToString() & vbcrlf) Console.WriteLine("cipherText1 = " & vbcrlf & cipherText1.ToString() & vbcrlf) Console.WriteLine("cipherText2 = " & vbcrlf & cipherText2.ToString() & vbcrlf) Console.WriteLine("plainText1 after decryption = " & plainText1after.ToString() & vbcrlf) Console.WriteLine("plainText2 after decryption = " & plainText2after.ToString() & vbcrlf) if plainText1before = plainText1after then Console.WriteLine("plainText1 -- OK" & vbcrlf) else Console.WriteLine("plainText1 -- NOT OK" & vbcrlf) end if if plainText2before = plainText2after then Console.WriteLine("plainText2 -- OK") else Console.WriteLine("plainText2 -- NOT OK") end if End Sub Private Function Encrypt(value as biginteger) as biginteger return biginteger.modpow(value,e,n) End Function Private Function Decrypt(value as biginteger) as biginteger return biginteger.modpow(value,d,n) End Function End Module End Namespace
run
|
edit
|
history
|
help
0
rotina de professores (select case)
CAI - Visual Basic - Libreria de funciones
Web application
Selected Poetry of Rumi ~ doy mod 119
If Function returns not Nothing for DateTime
do until ex 2
ex4
exercicio 3
CAI Visual Basic - Ej Citas
Poem of the day from 'Selected Poems of Rumi (Dover Thrift Edition)'