메뉴 건너뛰기

app

[clojure] RSA 알고리즘 구현체

suritam92013.04.09 02:53조회 수 2826댓글 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
    • 글자 크기
[fortify] C/C++ 진단하기 (by suritam9) [PAC] Proxy Auto Configuration (by suritam9)

댓글 달기

suritam9
2013.04.25 조회 5867
suritam9
2013.04.04 조회 2018
suritam9
2012.09.14 조회 2387
suritam9
2012.06.24 조회 2235
suritam9
2012.06.24 조회 2580
suritam9
2012.06.24 조회 2403
suritam9
2012.06.22 조회 2448
이전 1 2 3 4 5 6 7 8 9 10... 14다음
첨부 (3)
result.JPG
52.2KB / Download 26
key.jpg
87.8KB / Download 36
gen.jpg
12.9KB / Download 32
위로