메뉴 건너뛰기

app

[clojure] RSA 알고리즘 구현체

suritam92013.04.09 02:53조회 수 2811댓글 0

  • 3
    • 글자 크기

https://github.com/topher200/rsa-cryptography


위 사이트에 RSA 알고리즘이 구현되어 있다.


그런데, generate-key가 number format 때문에 error 가 나서, 강제 생성 하였다.


이를 실행해보기 위해서는 math.clj 가 필요하다.


https://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/math.clj?r=384


floor 랑 gcd 정도 쓰이는데, 없으면 또 잘 안된다.


find-tow-unique-primes 로 소수를 생성하고


gen.jpg


키 생성 원리에 따라 hashmap을 정의해 준다.


http://en.wikipedia.org/wiki/RSA_(algorithm)


result.JPG


암호화와 복호화가 됨을 확인할 수 있다.


n값인 modulus라 불리는 q와 p의 곱은 3634769239 이고, totient 라 부르는 값은 3634648360 이다.


totient를 이용해 encrypt-key 와 decrypt-key가 나오는데, 각각 65537, 1004981353 이다.


65537, 17, 3 가 enc로 거의 정해진 듯 하며, 


(defn modular-multiplicative-inverse

  "Determines the inverse cooresponding to a given a with respect to modules m.

  Research: http://en.wikipedia.org/wiki/Modular_multiplicative_inverse and

  http://numericalrecipes.blogspot.com/2009/03/modular-multiplicative-inverse.html"

  [a m]

  (let [[x y] (extended-gcd a m)]

    (big-integer (mod x m))))


에 의해, decript-key 가 결정된다.

 


error 나는 부분을 찾아서 수정했다.


modular-multiplicative-inverse 에서 output 이 소수일 경우 big-integer 를 호출할 때, int 가 아니어서 NumberFormatException 이 일어난다. 따라서 issue를 제기하고, 해당 내용을 고쳐서 성공할 수 있었다.


그런데, key bit-length를 12로 하면, 잘 되지 않는다.


key.jpg

suritam9 (비회원)
  • 3
    • 글자 크기
[evb] 조작번호 생성기 (by 박영식) [flash] 개체의 이동, 근접여부, 크기조절 (by 박영식)

댓글 달기

이전 1 ... 3 4 5 6 7 8 9 10 11 12... 14다음
첨부 (3)
result.JPG
52.2KB / Download 25
key.jpg
87.8KB / Download 35
gen.jpg
12.9KB / Download 30
위로