전체 64

[파이썬] cryptopals 1-5 문제풀이 (Implement repeating-key XOR)

주소 http://cryptopals.com/sets/1/challenges/5/ 문제Implement repeating-key XORHere is the opening stanza of an important work of the English language:Burning 'em, if you ain't quick and nimble I go crazy when I hear a cymbalEncrypt it, under the key "ICE", using repeating-key XOR.In repeating-key XOR, you'll sequentially apply each byte of the key; the first byte of plaintext will be XOR'd against ..

[파이썬] cryptopals 1-4 문제풀이 (Detect single-character XOR)

주소 http://cryptopals.com/sets/1/challenges/4/ 문제Detect single-character XOROne of the 60-character strings in this file has been encrypted by single-character XOR. Find it. (Your code from #3 should help.)[출처] [파이썬] cryptopals 1-4 문제풀이 (Detect single-character XOR)|작성자 설퐁 해석이번엔 여러문장을 xor브루트포싱해서 정상적인 한문장을 고르는겁니다! 1-3코드를 가져와서 약간 수정해서 사용합니다. 알파벳만 골라냈더니 잘 안나옵니다. 공백도 추가합니다. 코드123456789101112131415161..

[파이썬] cryptopals 1-3 문제풀이 (Single-byte XOR cipher)

주소 http://cryptopals.com/sets/1/challenges/3/ 문제Single-byte XOR cipherThe hex encoded string:1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736... has been XOR'd against a single character. Find the key, decrypt the message.You can do this by hand. But don't: write code to do it for you.How? Devise some method for "scoring" a piece of English plaintext. Character frequency is a..

[파이썬] cryptopals 1-2 문제풀이 (Fixed XOR)

주소 http://cryptopals.com/sets/1/challenges/2/ 문제Fixed XORWrite a function that takes two equal-length buffers and produces their XOR combination. If your function works properly, then when you feed it the string:1c0111001f010100061a024b53535009181c... after hex decoding, and when XOR'd against:686974207468652062756c6c277320657965... should produce:746865206b696420646f6e277420706c6179[출처] [파이썬] c..

[파이썬] cryptopals 1-1 문제풀이 (Convert hex to base64)

주소 http://cryptopals.com/sets/1/challenges/1/ 문제Convert hex to base64The string:49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6dShould produce:SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29tSo go ahead and make that happen. You'll need to use this code for the rest of the exercises. [출처] [파이썬] cryptopals 1-1 문제풀이 (Convert hex to ba..

[Project Euler]프로젝트 오일러 Problem 8 (1000자리 숫자 안에서 이어지는 5자리 숫자의 곱 중 최대값은?)

설명 http://euler.synap.co.kr/ 8번 문제입니다. 문제 다음은 연속된 1000자리 숫자입니다 (읽기 좋게 50자리씩 잘라놓음). 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 62229893423380308135336276614282806444486645238749 303589072..

[Project Euler]프로젝트 오일러 Problem 7 (10001번째의 소수)

설명 http://euler.synap.co.kr/ 7번 문제입니다. 문제 소수를 크기 순으로 나열하면 2, 3, 5, 7, 11, 13, ... 과 같이 됩니다. 이 때 10,001번째의 소수를 구하세요. 코드파이썬 2.7 123456789101112def is_sosu(n): for i in range(2,n): if n%i == 0: return 0 return 1 count = 0for i in range(2,1000000): if is_sosu(i): count+=1 if count == 10001: print ics 할말별다른 알고리즘을 사용하지 않아서 1~2분 걸립니다. 2의배수 3의배수 등을 걸러내면 속도가 조금 줄어듭니다.

[Project Euler]프로젝트 오일러 Problem 6 (1부터 100까지 "제곱의 합"과 "합의 제곱"의 차는?)

설명 http://euler.synap.co.kr/ 6번 문제입니다. 문제 1부터 10까지 자연수를 각각 제곱해 더하면 다음과 같습니다 (제곱의 합). 1^2 + 2^2 + ... + 10^2 = 385 1부터 10을 먼저 더한 다음에 그 결과를 제곱하면 다음과 같습니다 (합의 제곱). (1 + 2 + ... + 10)^2 = 55^2 = 3025 따라서 1부터 10까지 자연수에 대해 "합의 제곱"과 "제곱의 합" 의 차이는 3025 - 385 = 2640 이 됩니다. 그러면 1부터 100까지 자연수에 대해 "합의 제곱"과 "제곱의 합"의 차이는 얼마입니까? 코드파이썬 2.7 123456result = 0result2 = 0for i in range(1,100): result += i**2 result2..

[Project Euler]프로젝트 오일러 Problem 5 (1 ~ 20 사이의 어떤 수로도 나누어 떨어지는 가장 작은 수)

설명 http://euler.synap.co.kr/ 5번 문제입니다. 문제 1 ~ 10 사이의 어떤 수로도 나누어 떨어지는 가장 작은 수는 2520입니다. 그러면 1 ~ 20 사이의 어떤 수로도 나누어 떨어지는 가장 작은 수는 얼마입니까? 코드파이썬 2.7 123456for i in range(20,1000000000,20): for a in range(1,20): if i%a != 0: break if a >= 19: print i

[Project Euler]프로젝트 오일러 Problem 4 (세자리 수를 곱해 만들 수 있는 가장 큰 대칭수)

설명 http://euler.synap.co.kr/ 4번 문제입니다. 문제 앞에서부터 읽을 때나 뒤에서부터 읽을 때나 모양이 같은 수를 대칭수(palindrome)라고 부릅니다. 두 자리 수를 곱해 만들 수 있는 대칭수 중 가장 큰 수는 9009 (= 91 × 99) 입니다. 세 자리 수를 곱해 만들 수 있는 가장 큰 대칭수는 얼마입니까? 코드 파이썬 2.71234567891011121314def is_palin(n): length = len(str(n))/2 for i in range(0,length): if str(n)[i] != str(n)[-i-1]: return 0 return 1 result = 0 for a in range(100,1000): for b in range(100,1000): i..