ssongk
ssongk
ssongk
전체 방문자
오늘
어제

공지사항

  • resources
  • 분류 전체보기 (626)
    • CTF (24)
    • background (79)
      • fuzzing (5)
      • linux (29)
      • linux kernel (15)
      • windows (2)
      • web assembly (1)
      • embedded (0)
      • web (13)
      • crypto (9)
      • mobile (1)
      • AI (1)
      • etc.. (3)
    • write-up(pwn) (171)
      • dreamhack (102)
      • pwn.college (4)
      • pwnable.xyz (51)
      • pwnable.tw (3)
      • pwnable.kr (5)
      • G04T (6)
    • write-up(rev) (32)
      • dreamhack (24)
      • reversing.kr (8)
    • write-up(web) (195)
      • dreamhack (63)
      • LOS (40)
      • webhacking.kr (69)
      • websec.fr (3)
      • wargame.kr (6)
      • webgoat (1)
      • G04T (7)
      • suninatas (6)
    • write-up(crypto) (19)
      • dreamhack (16)
      • G04T (1)
      • suninatas (2)
    • write-up(forensic) (53)
      • dreamhack (5)
      • ctf-d (47)
      • suninatas (1)
    • write-up(misc) (13)
      • dreamhack (12)
      • suninatas (1)
    • development (31)
      • Linux (14)
      • Java (13)
      • Python (1)
      • C (2)
      • TroubleShooting (1)
    • 자격증 (8)
    • 이산수학 (1)
    • 정보보안 (0)
hELLO · Designed By 정상우.
ssongk

ssongk

[CryptoHack] Quadratic Residues (제곱 잉여)
background/crypto

[CryptoHack] Quadratic Residues (제곱 잉여)

2023. 7. 1. 19:42

Quadratic Residues는 제곱 잉여 또는 이차 잉여 라고 부른다.

위키에서 다음과 같이 설명한다.

wikipedia


 

크립토핵에선 모듈로 p = 29를 예시로 든다.

정수 a = 11을 취하고 a^2 = 5 mod 29를 계산해보자.

a % p = 11, a^2 % p = 5이므로 5의 제곱근은 11이다.

 

이번엔 18의 제곱근을 구해보자.

제곱근을 찾기 위해 a^2 = 18 mod 29를 만족하는 수 a를 찾아야 한다.

하지만 0 ~ 28까지의 수 중에서 만족하는 수가 없다.

 

이렇게 식 a^2 = x mod p 를 만족하는 a가 존재할 때

정수 x는 a에 대한 제곱 잉여라고 할 수 있다.

위키에서 이러한 제곱 잉여는 홀수인 소수 p에 대하여 (p-1)/2 개가 존재한다고 한다.

 

연습 문제는 다음과 같다.

# 아래 목록에는 제곱 비잉여 2개와 제곱 잉여 1개가 있습니다.
# 제곱 잉여를 찾은 다음 제곱근을 계산하여 두 개의 가능한 루트 중 더 작은 것을 플래그로 제출하십시오.
p = 29
ints = [14, 6, 11]

 

0부터 28까지 총 29개로 그렇게 많지 않으므로 전수 조사가 가능하다.

p = 29
ints = [14, 6, 11]

for x in ints:
    for a in range(p):
        if pow(a,2,p) == x:
            print(x,a)
            break
6 8

 

정답은 8이다.

 


레퍼런스

https://cryptohack.org/courses/modular/root0/

 

CryptoHack – Home

A fun, free platform to learn about cryptography through solving challenges and cracking insecure code. Can you reach the top of the leaderboard?

cryptohack.org

https://ko.wikipedia.org/wiki/%EC%A0%9C%EA%B3%B1_%EC%9E%89%EC%97%AC

 

제곱 잉여 - 위키백과, 우리 모두의 백과사전

위키백과, 우리 모두의 백과사전. 수론에서, 정수 n {\displaystyle n} 에 대해, a {\displaystyle a} 가 n {\displaystyle n} 의 제곱잉여(이차잉여)(二次剩餘, 영어: quadratic residue) 라는 것은 x 2 = a {\displaystyle x^{2}

ko.wikipedia.org

 

'background > crypto' 카테고리의 다른 글

[CryptoHack] Modular Square Root (Tonelli-Shanks algorithm)  (0) 2023.07.06
[CryptoHack] Legendre Symbol (르장드르 기호)  (0) 2023.07.04
[CryptoHack] Modular Inverting (모듈로 역수)  (0) 2023.07.01
[CryptoHack] Modular Arithmetic 2  (0) 2023.07.01
[CryptoHack] Modular Arithmetic 1  (0) 2023.07.01
    'background/crypto' 카테고리의 다른 글
    • [CryptoHack] Modular Square Root (Tonelli-Shanks algorithm)
    • [CryptoHack] Legendre Symbol (르장드르 기호)
    • [CryptoHack] Modular Inverting (모듈로 역수)
    • [CryptoHack] Modular Arithmetic 2
    ssongk
    ssongk
    벌레 사냥꾼이 되고 싶어요

    티스토리툴바