C언어로 서로소인지 확인하는 절차에서 오류가 납니다..

Maylop@Google의 이미지

입력값 K1과 26이 서로소가 아니면 종료시키려 하는데 이런 오류가 뜹니다
" 식이 수정할 수 있는 Ivalue여야 합니다"

K1은 int형이구요 코드는 이렇습니다. 어떻게 해야 오류를 없앨 수 있을까요..

printf("\nK1 값을 입력하세요 (단, K1은 1과 25 사이의 수)\n");
    scanf("%d", &K1);
 
    if (K1 < 1 || K1>25)
    {
        printf("K1 값이 조건에 맞지 않습니다. \n");
        exit(0);
    }
 
 
// 서로소인지 확인
    if (K1 % 2=0)
    {
        printf("역함수가 존재 하지 않는 키 값 입니다.");
        exit(0);
    }
    else if (K1 % 13=0)
    {
        printf("역함수가 존재 하지 않는 키 값 입니다.");
        exit(0);
    }
    else if (K1 % 26=0)    
    {
        printf("역함수가 존재 하지 않는 키 값 입니다.");
        exit(0);
    }
    else
    {
        printf("역함수가 존재하는 키 값 입니다.");
    }
익명 사용자의 이미지

= -> ==

p.s. RSA 비슷한 거라도 구현하고 계십니까?

Maylop@Google의 이미지

아아아아... 그걸 생각 못했네요.. 감사합니다..

네 암호학을 배우는 대학생 인지라 Affine 암호를 구현해보려고 아등바등 중입니다!

ㅇㅇ의 이미지

k1과 26이 서로소인지 검증해야 하니까 k1과 26을 gcd에 넣어서 리턴 값이 1이면 서로소임을 이용하는 거요.

Maylop@Google의 이미지

음.. 좋은 방법 알려주신 것 같지만 gcd를 어떻게 구현해야 될지 감이 안잡히네요..

익명 사용자의 이미지

1. 저라면 26과 서로소인지 체크하려면 그냥 (a % 2) && (a % 13) 할 겁니다.

26의 소인수래봤자 두 개밖에 안 되는데 소 잡는 칼 쓸 필요가 딱히 없죠.

2. gcd를 계산하는 방법 중 가장 널리 알려진 방법은 Euclidean algorithm입니다.

이 알고리즘은 단 한 줄로 요약됩니다: gcd(a, b) = gcd(b, a % b)

옛날에는 위 식을 증명하는 게 고등학교 수학 교과과정에 있었던 것 같은데, 요즘은 어떤지 모르겠네요.

다만 실제로 컴퓨터로 구현했을 때는 Stein's algorithm이 좀 더 효율적인 편이라고 합니다.

https://en.wikipedia.org/wiki/Binary_GCD_algorithm

3. 이 알고리즘들에 대해 잘 모르신다면, 음, 아마 중간고사 지나고 RSA 진도나갈때쯤 배우게 될거에요.

암호론 수강중인데 정수론, 유한체론에 기초가 없다면 예습을 좀 미리 해 두는 게 좋을 겁니다.

안 그러면 수학과에서 마실 나온 학생들한테 기말고사 즈음 양학 당할 가능성이 높아요 ㄷㄷ.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.