Translate

2017年1月27日星期五

[ root-me ]Shift cipher

In a shift-ciphered text the key consists of only one character: it is added (modulo 256) for each of the character of the original message to obtain the ciphertext.
Since the key space is only of 256 elements is not a problem do a bruteforce and visually inspect each transposition to find a message with sense.
The following python code solves the challenge:
  1. with open('ch7.bin') as f:
  2. msg = f.read()
  3. for x in range(256):
  4. print ''.join([chr((ord(y) + x) % 256) for y in msg])


shift cipher,经典的密码类型,透过字母的位移来达成简易的加密,最有名的例子就是Caesar cipher凯萨加密法。
题目提供了一个binary档案,里面有一串密文:
L|ky+*^*zo*kvsno|*kom*vo*zk}}*cyvksr
稍微观察一下,发现「*」一直出现。其实还满好猜测的,如果是一个句子,会一直出现的不外乎就是「空格」,查一下ASCII表格,空格是32,而星号则是42,推测位移量应该是10,写个简单的程式转换一下字串:
1
2
3
4
5
<?php
$file = fopen( "ch7.bin" , "r" );
$code = str_split(fgets($file));
for ($i = 0 ; $i < count($code) ; $i++)
echo chr(ord($code[$i]) - 10 );
输出结果是一串法文,不过没关系,我们只要看懂pass就是知道后面那个字串应该就是密码了:

Bravo! Tu peux valider avec le pass Yolaihu









沒有留言:

發佈留言