Play CTF to learn cryptography 2: Caesar (Caesar code), Morse (Morse code), secondary base64+Unicode to ASCii code

CTF Cryptography 2:

1. Caesar password:

Insert picture description here
It’s not that I said, I was really puzzled at the beginning of this question. First: He said that there are a pair of characters on the lantern. I originally thought that this pair of characters was a key and a plaintext. Until I opened the attachment, it must not be the key. Ah:
Insert picture description here
You can see here that our attachment looks like this. It may be plaintext or ciphertext. Looking back at the previous question, the format of the answer is: cyberpeace{XXXX}, what does this mean? It means that the curly brackets in this attachment are cyberpeace, and the curly brackets are not encrypted or decrypted, which means that the algorithm can not control the curly brackets. Add the title of this question: Caesar, indicating that it is Caesar's algorithm. We know that the Caesar encryption algorithm is a classical symmetric encryption algorithm, which requires a key as the shift step, but what about the key for this problem? We know that the format of the answer should be cyberpeace, so the first character is compared:'o'-'c' = 12,
so this shift requires 12 steps (circular movement) backward for each character.

Solution: The
Caesar encryption algorithm is: C = E(k, p) = (p + k) mod 26 The
Caesar decryption algorithm is: p = D(k, C) = (C-k) mod 26

According to the above observation, we get the need to reverse key = 12, so this is decryption, the code is as follows:


public class Caesar {
    
    
	
	static String src = "oknqdbqmoq{kag_tmhq_xqmdzqp_omqemd_qzodkbfuaz}";
	
	public static void main(String[] args) {
    
    
		StringBuffer ans = new StringBuffer("");
		
		for(int i = 0;i < src.length();++i) {
    
    
			if(src.charAt(i) >= 'a' && src.charAt(i) <= 'z')
			{
    
    
				char iChar = (char)((src.charAt(i) - 'a' - 12 + 26) % 26 + 'a');
				ans.append(iChar);
			}
			else
				ans.append(src.charAt(i));
		}
		
		System.out.println(ans);
		
	}
}

In addition, the Caesar password also has an online solution URL:

Caesar password online encryption/decryption

2. Morse password:

Insert picture description here

After opening this question, the attachment is: I
Insert picture description heregot this 01 string, originally I thought it was binary and then compared the ASCii code... Then I saw the title of the question: Morse, indicating that it is a Morse code. To be honest, I have never learned Morse password, and then I went to learn it and saw this Morse password comparison table:

Insert picture description here
Then we can see that the ciphertext comparison of this Morse password is composed of:'-' and'.', and our attachments are 0 and 1, so what kind of correspondence is it? We don’t know, but we know that the final plaintext format starts with cyberpeace. Let's take a look. The first one at the beginning is 11, which should correspond to the character'c'. First, the length of the ciphertext key is 2. Unfortunately, the length on the password table is 2 and the characters are the same (after all, 11 is the same character ) The only comparison is: M...... Isn't this solution beginning with cyberpeace? ? ?
But this way at least we have determined one point, 1 corresponds to'-', 0 corresponds to '.'

Solution: or Java programming

import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;

public class Morse {
    
    
	
	static String src = "11 111 010 000 0 1010 111 100 0 00 000 000 111 00 10 1 0 010 0 000 1 00 10 110";
	
	public static void main(String[] args) {
    
    
		src = src.replace('1', '-');
		src = src.replace('0', '.');
		
		HashMap<String, String> mp = new HashMap<>();
		mp.put("a", ".-");
		mp.put("b", "-...");
		mp.put("c", "-.-.");
		mp.put("d", "-..");
		mp.put("e", ".");
		mp.put("f", "..-.");
		mp.put("g", "--.");
		mp.put("h", "....");
		mp.put("i", "..");
		mp.put("j", ".---");
		mp.put("k", "-.-");
		mp.put("l", ".-..");
		mp.put("m", "--");
		mp.put("n", "-.");
		mp.put("o", "---");
		mp.put("p", ".-");
		mp.put("q", "--.-");
		mp.put("r", ".-.");
		mp.put("s", "...");
		mp.put("t", "-");
		mp.put("u", "..-");
		mp.put("v", "...-");
		mp.put("w", ".--");
		mp.put("x", "-..-");
		mp.put("y", "-.--");
		mp.put("z", "--..");
		mp.put("0", "-----");
		mp.put("1", ".----");
		mp.put("2", "..---");
		mp.put("3", "...--");
		mp.put("4", "....-");
		mp.put("5", ".....");
		mp.put("6", "-....");
		mp.put("7", "--...");
		mp.put("8", "---..");
		mp.put("9", "----.");
		
		HashMap<String, String> MorseDec = new HashMap<>();
		Set<Entry<String, String> > entrySet = mp.entrySet();
		for(Entry<String, String> entry : entrySet) 
			MorseDec.put(entry.getValue(), entry.getKey());
		
		StringBuffer StrTemp = new StringBuffer("");
		StringBuffer ans = new StringBuffer("");
		for(int i = 0;i < src.length();++i) {
    
    
			if(' ' == src.charAt(i))
			{
    
    
				ans.append(MorseDec.get(StrTemp.toString()));
				StrTemp = new StringBuffer("");
			}
			else
				StrTemp.append(src.charAt(i));
		}
		ans.append(MorseDec.get(StrTemp.toString()));
		System.out.println(ans);
	}
}

Calculate the result:
Insert picture description here
Then you must remember to follow the format he said, the answer is:

cyberpeace {morsecodeissointeresting}

Three, a comprehensive question: mixed coding

Insert picture description here
First of all, I got the attachment and looked at it. It was a complicated one:
Insert picture description here
First of all, this is Nima... But do you remember the last cryptography blog? When we talked about base64 encryption, we talked about adding a set of 0s to the back if there are less than 6 digits, and then the 6-bit encoding represented by the character'=', which is completely composed of the added 0s. There are two equal signs at the end, which reminds us Should we use base64 for decryption? This is so long, let's try it (fortunately, I wrote a Java program yesterday): The
Insert picture description here
program ran out with such a large number of things, which made me a little annoying! But let's take a look, it seems that these numbers are regular! If it’s the ASCii code, that’s great, but when you look closely, the title says that the answers are all lowercase letters... But these have already broken through the range of lowercase letters in the ASCii code (97-122). It's Unicode encoding... What are the characteristics of Unicode encoding? By then, I will know which encoding format it is!

Encoding format converter: great tool!

Encoding format converter!

Insert picture description here

Unicode encoding: the first 128 characters are the ASCII code, followed by the extension code. In the Unicode code, each character block is based on the same standard. Hieroglyphs in Chinese, Korean, and Japanese occupy codes from 0X3000 to 0X9FFF.
Now that we have obtained the ASCii encoding converted from Unicode, let's continue to see...why is it still such a long ciphertext...
Continue to try base64 for secondary decryption:
Insert picture description here
we can see that this number looks like...and The lowercase letters corresponding to our ASCii code are relative!
Continue to parse this ASCii code: It’s
Insert picture description here
not that I said, the comprehensive question is still a bit difficult, for me like a CTF novice ... But just get the Flag!
Finally got the answer:
cyberpeace{welcometoattackanddefenceworld}

My complete code for this question:

import java.util.Base64;

public class base64 {
    
    
	static String src = "JiM3NjsmIzEyMjsmIzY5OyYjMTIwOyYjNzk7JiM4MzsmIzU2OyYjMTIwOyYjNzc7JiM2ODsmIzY5OyYjMTE4OyYjNzc7JiM4NDsmIzY1OyYjNTI7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LzExNi85Ny85OS8xMDcvOTcvMTEwLzEwMC8xMDAvMTAxLzEwMi8xMDEvMTEwLzk5LzEwMS8xMTkvMTExLzExNC8xMDgvMTAw";
	public static void main(String[] args) {
    
    
		
		/* 加密 */
//		String Encode = Base64.getEncoder().encodeToString(src.getBytes());
//		System.out.println(Encode);
		
		
		/* 解密 */
		byte[] Decode1 = Base64.getDecoder().decode(src);
		System.out.println(new String(Decode1));
		
		/* 二次解密 */
		byte[] Decode2 = Base64.getDecoder().decode(NextSrc);
		
		String ansAscii = new String(Decode2);
		System.out.println(ansAscii);
		
//		String dec2 = Decode1.toString();
//		byte[] Decode2 = Base64.getDecoder().decode(dec2);
//		System.out.println(new String(Decode2));
		
		StringBuffer Temp = new StringBuffer(""), res = new StringBuffer("");
		for(int i = 0;i < ansAscii.length();++i) {
    
    
			if('/' == ansAscii.charAt(i) && 0 != i)
			{
    
    
				int resTemp = Integer.parseInt(Temp.toString());
				res.append((char)(resTemp));
				Temp = new StringBuffer("");
			}
			else if('0' <= ansAscii.charAt(i) && ansAscii.charAt(i) <= '9')
				Temp.append(ansAscii.charAt(i));
		}
		int resTemp = Integer.parseInt(Temp.toString());
		res.append((char)(resTemp));
		System.out.println(res);
		
	}
	
}

Guess you like

Origin blog.csdn.net/qq_44274276/article/details/105385951