RSA 알고리즘의 C 코드는 구글에서 찾아보면 쉽게 얻을 수 있습니다...

간단히 참고 할 만한 C 소스 파일들을 보면 ...

1. http://www.codase.com/search/display?file=L2dlbnRvbzIvdmFyL3RtcC9yZXBvcy9jb2Rhc2UuYy9wYWtldHRvLTEuMTAtcjEvd29yay9wYWtldHRvLTEuMTAvbGlidG9tY3J5cHQvcnNhLmM=&lang=c

2. http://en.pudn.com/downloads3/sourcecode/crypt/detail11349_en.html

이 정도가 되겠지만 ... ... 둘 다 쉽지 않습니다.

그나마 2번 vlong class를 이용한 소스코드는 그나마 볼만한 수준이지만, 1번 소스 코드는 참고하기 어렵지요 ...

이는 RSA에서 사용하는 [매우 큰 정수]의 연산을 지원하는 함수,
하다못해 덧셈 뺄셈과 같은 기본 연산도 새로 구성해줘야 하기 때문인데

.NET Framework 4.0부터는 이를 해결하기 위한 BigInteger class가 생겼습니다.

C#으로 간단히 RSA 연산을 구현하면 아래의 코드와 같습니다.
(소스 코드는 이전 포스트 : http://reinliebe.tistory.com/79 에 올린 RSA 예제를 사용했습니다)

using System;

using System.Numerics;

 

class RSA_TEST

{

    static void Main(string[] args)

    {

        BigInteger d = new BigInteger(422191);

        BigInteger n = new BigInteger(6012707);

        BigInteger e = new BigInteger(3674911);

        BigInteger M = new BigInteger(5234673);

        BigInteger C = new BigInteger();

 

        // Encryption

        C = BigInteger.ModPow(M, e, n);

        Console.WriteLine("Cipertext : "+C);

 

        // Decryption

        M = BigInteger.ModPow(C, d, n);

        Console.WriteLine("Plaintext : " + M);

    }

}

▷ 결과


p.s Ciphertext 에서 h 빠진건 ... 애교로 봐주세요 ... ;ㅂ;

출처 - http://reinliebe.tistory.com/

+ Recent posts