+91 94 448 29 228 --- E-Mail ID:networksimulators2@gmail.com

rsa ns2

What is rsa?

  • RSA is a cryptosystem for public-keyencryption, and is widely used for securing sensitive data, particularly when being sent over an insecure network.
  • Ron Rivest, Adi Shamir, and Leonard Adleman introduced a cryptographic algorithm.
  • The RSAalgorithm is based on the fact that there is no efficient way to factor very large numbers. Deducing an RSA key, therefore, requires an extraordinary amount of computer processing power and time.

Advantages of RSA algorithm:

  •  Gives high speed for encryption.
  • Generating unknown private keys.
  • New applications can be added without updating the chip.
  • Chip has SED algorithm and all other features of classisSys.


Procedure Involved in RSA NS2 Projects

Sample RSA NS2 Code

     proc rsa_encrypt {
input skey
} {
         upvar $skey key
 
        if {
[bitsize $key(n)] < [bitsize $input]
} {
             error "keysize [bitsize $key(n)] must be greater than text [bitsize $input]/$input"
         }
        return [powm $input $key(e) $key(n)]
     }
 
proc rsa_decrypt {
input skey
} {         upvar $skey key
         if {
[bitsize $key(n)] < [bitsize $input]
} {
 
            error "keysize [bitsize $key(n)] must be greater than text [bitsize $input]/$input"
  }
         if {
!
} { return [rsa_slow_decrypt $input key] } set m1 [powm $input [fdiv_r $key(d) [sub_ui $key(p) 1]] $key(p)] set m2 [powm $input [fdiv_r $key(d) [sub_ui $key(q) 1]] $key(q)] set h [sub $m2 $m1] if { [cmp_si $h 0] < 0 } { set h [add $h $key(q)] } set h [fdiv_r [mul $key(u) $h] $key(q)] set m [add $m1 [mul $h $key(p)]] return $m } proc rsa_slow_decrypt { input pkey } { upvar $pkey key if { [bitsize $key(n)] < [bitsize $input] } { error "keysize [bitsize $key(n)] must be greater than text [bitsize $input]/$input" } if { [catch { set ptext [powm $input $key(d) $key(n)] }] } { puts "rsa_slow_decrypt: $input [hex $key(d)] [hex $key(n)]" error "powm error" } return $ptext } proc pack_text { ptext keylen } { while { [string length $ptext] < ($keylen - 16) } { append ptext [binary format H* [::md5::md5 $ptext]] } if { [string length $ptext] < $keylen } { set md5 [binary format H* [::md5::md5 $ptext]] append ptext [string range $md5 0 [expr $keylen - [string length $ptext] - 1]] } binary scan $ptext H* hex return [convert 0x$hex] } proc encrypt { ptext pkey } { upvar $pkey key set keylen [bytesize $key(n)] set en [pack_text $ptext $keylen] set en [rsa_encrypt $en key] append ctext [hex $en] set ctext [binary format H* $ctext] return $ctext }


NS2 Member Accounts | |
© 2005 - 2018 Vanet Projects

© 2005 - 2018 Matlab Projects