Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #4.
- source ( "publica/clavesdh.R" )
- # Diffie-Hellman
- p <- 13 ; g <- 2
- yA <- 3 ; yB <- 6
- # log2(6) = 5 mód 13.
- # 6 = 2^5 mod 13
- for (i in 1 :(p- 1 )){
- if (potmod(g,i,p) == yA){
- xA <- i
- }
- }
- cat(c( "xA = " , xA),sep= "" )
- for (i in 1 :(p- 1 )){
- if (potmod(g,i,p) == yB){
- xB <- i
- }
- }
- cat(c( "xB = " , xB),sep= "" )
- dh <- clavesdh(p,g,xA,xB)
- cat(c( "K = " , dh[ 3 ]),sep= "" )
- cat(c( "xA = " , xA, "; xB = " , xB, "; K = " , dh[ 3 ]),sep= "" )
- # xA = 4; xB = 5; K = 9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement