一些Misc的Writeup - 2

一些Misc的Writeup - 2

1. Character Encoding

題目描述

In the computing industry, standards are established to facilitate information interchanges among American coders. Unfortunately, I’ve made communication a little bit more difficult. Can you figure this one out? 41 42 43 54 46 7B 34 35 43 31 31 5F 31 35 5F 55 35 33 46 55 4C 7D

題目思路

我們觀察編碼,很容易發現它的特徵:UTF-8.有數字和字母,而且已經兩兩斷開,字母是大寫。

題目解決

我們需要將空格換成百分號%,這裏可以用word的查找替換。

最後放入UTF-8解碼工具

題目答案

ABCTF{45C11_15_U53FUL}

2. Hextroadinary

題目描述

Meet ROXy, a coder obsessed with being exclusively the worlds best hacker. She specializes in short cryptic hard to decipher secret codes. The below hex values for example, she did something with them to generate a secret code, can you figure out what? Your answer should start with 0x.

0xc4115 0x4cf8

題目思路

題中給出了兩個16進制數,讓我們輸出的也是十六進制數(Your answer should start with 0x.)經過觀察發現題目中的名字ROXy別具深意,ROX 倒過來是 xor 異或。所以我們想到了將其轉化為二進制求兩個數的異或,再轉換回十六進制。

要注意的是,輸出的格式是 CTFlearn{…}

題目解決

進制轉換

4cf8–>100110011111000

c4115–>11000100000100010101

求異或

題目答案

CTFlearn{c0ded}

3. Base 2 2 the 6

題目描述

There are so many different ways of encoding and decoding information nowadays… One of them will work! Q1RGe0ZsYWdneVdhZ2d5UmFnZ3l9

題目思路

觀察題目,發現Base 6 2 2 ,嚴重懷疑是base64編碼。而且給出的字符串也具有base64的特徵,有大小寫,字母和數字。

題目解決

base64的編碼一定會被4整除,不能的後面加等號=。

在綫base64解碼

題目答案

CTF{FlaggyWaggyRaggy}

4. Morse Code

題目描述

..-. .-.. .- –. … .- – ..- . .-.. – — .-. … . .. … -.-. — — .-.. -… -.– - …. . .– .- -.– .. .-.. .. -.- . -.-. …. . . …

題目思路

由題目可知,這就是簡單的莫斯密碼。

題目解決

莫斯密碼解密

題目答案

FLAGSAMUELMORSEISCOOLBYTHEWAYILIKECHEES

5. Vigenere Cipher

題目描述

The vignere cipher is a method of encrypting alphabetic text by using a series of interwoven Caesar ciphers based on the letters of a keyword.

I’m not sure what this means, but it was left lying around: blorpy

gwox{RgqssihYspOntqpxs}

題目思路

很顯然,這是古典密碼中的維吉尼亞密碼。用python解決。

題目解決

用python編寫程序:源碼如下

####Vigenere密码###
 
letter_list='ABCDEFGHIJKLMNOPQRSTUVWXYZ'  #字母表
 
#根据输入的key生成key列表
def Get_KeyList(key):
  key_list=[]
  for ch in key:
    key_list.append(ord(ch.upper())-65)
  return key_list
  
#加密函数
def Encrypt(plaintext,key_list):
  ciphertext=""
  i=0
  for ch in plaintext:  #遍历明文
    if 0==i%len(key_list):
      i=0
    if ch.isalpha():  #明文是否为字母,如果是,则判断大小写,分别进行加密
      if ch.isupper():  
        ciphertext+=letter_list[(ord(ch)-65+key_list[i]) % 26]
        i+=1
      else:
        ciphertext+=letter_list[(ord(ch)-97+key_list[i]) % 26].lower()
        i+=1
    else: #如果密文不为字母,直接添加到密文字符串里
      ciphertext+=ch
  return ciphertext
  
#解密函数
def Decrypt(ciphertext,key):
  plaintext=""
  i=0
  for ch in ciphertext: #遍历密文
    if 0==i%len(key_list):
      i=0
    if ch.isalpha():  #密文为否为字母,如果是,则判断大小写,分别进行解密
      if ch.isupper():
        plaintext+=letter_list[(ord(ch)-65-key_list[i]) % 26]
        i+=1
      else:
        plaintext+=letter_list[(ord(ch)-97-key_list[i]) % 26].lower()
        i+=1
    else: #如果密文不为字母,直接添加到明文字符串里
      plaintext+=ch
  return plaintext
 
if __name__=='__main__':
  print("加密请按D,解密请按E:")
  user_input=input();
  while(user_input!='D' and user_input!='E'):#输入合法性判断
    print("输入有误!请重新输入:")
    user_input=input()
  
  print("请输入密钥:")
  key=input()
  while(False==key.isalpha()):#输入合法性判断
    print("输入有误!密钥为字母,请重新输入:")
    key=input()
  
  key_list=Get_KeyList(key)
  
  if user_input=='D':
    #加密
    print("请输入明文:")
    plaintext=input()
    ciphertext=Encrypt(plaintext,key_list)
    print("密文为:\n%s" % ciphertext)
  else:
    #解密
    print("请输入密文:")
    ciphertext=input()
    plaintext=Decrypt(ciphertext,key_list)
    print("明文为:\n%s" % plaintext)

題目答案

flag{CiphersAreAwesome}

6. RSA Twins!

題目描述

https://wwx.lanzoux.com/iVaI8jxyplc Aww, twins :). They’re so cute! They must be (almost) identical because they âre the same except for the slightest difference. Anyway, see if you can find my flag. Hint: This is just math. You’re probably not going to find any sort of specialized attack.、

題目思路

題目中說這是一個數學問題,應該就是傑出結果。對於RSA,有 p、q、n、φ(n)、e、d五個數字,其中關係是,n是一個很大的能分解為兩個質數p、q乘機的數,φ(n)=(p-1)*(q-1),e是公鑰,是随机选择的,条件是1< e < φ(n),且e与φ(n) 互质(常選65537)。d是私鑰,即模反元素,ed ≡ 1 (mod φ(n)),其實相當於ed + φ(n)y = 1。求解出的數字在進行相應的解密。

題目解決

題目數據如下

n = 14783703403657671882600600446061886156235531325852194800287001788765221084107631153330658325830443132164971084137462046607458019775851952933254941568056899

e = 65537

c = 684151956678815994103733261966890872908254340972007896833477109225858676207046453897176861126186570268646592844185948487733725335274498844684380516667587

l所以可以得知,我們要根據n和e求出d,並對c進行解密。

第一步是分解大數

於是我們得到p、q,以及能算出φ(n)。

然後求模反元素d,我們採用拓展歐幾里得算法 python算法如下:

def ext_euclid(a, b):
    old_s,s=1,0
    old_t,t=0,1
‘’    old_r,r=a,b
    if b == 0:
        return 1, 0, a
    else:
        while(r!=0):
            q=old_r//r
            old_r,r=r,old_r-q*r
            old_s,s=s,old_s-q*s
            old_t,t=t,old_t-q*t
    return old_s

得到私鑰我們對c進行解密,公式cd≡ m (mod n),python中即m=pow(c,d,n) 於是我們拿到了解密後的一串數字2511413510841857968238260398011789038678337904998872216445

要拿到flag,我們想到的一般就是base64編碼。

將其轉換為base64,python算法如下:

###10進制數轉換base64###
def p64(n):
    table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"#碼錶
    result = []
    temp = n
    print(temp%64)
    if 0==temp:
        result.append("0")
    else:
        while 0 <temp:
            result.append(table[int(temp%64)])
            temp //= 64
    return ''.join([x for x in reversed(result)])

然後在綫base64解碼 就得到了flag。

題目答案

flag{i_l0v3_tw1N_pr1m3s}

7.

#CTF #Writeup #Cryptography
0%