东京大学加密招生海报解密过程-C++01字符串转换为大端二进制文件

#include<iostream>
#include <Winsock2.h>
using namespace std;

#pragma comment(lib, "ws2_32.lib")

const char* p = 
"00011111100010110000100000000000000000000000000000000000000000000000001000000011011011010101000011001011010011"
"10110000100100000000010100001111010101001100011110100001010101101010110101100000001110000000000011010100001101"
"10000101000100010011011010001110001000010110001100010011000110101100010011000011010010011010011000001101100010"
"11100000011010011010101001010111100001110100010011011001110101100000001011000011110111010010111101110010111000"
"11010110000001010010011000101110111111000000000011111111110000111000111101110000111000011110001100010110010011"
"01000011001000100110010011110011001001110010111001111101111001111010010011011110111110111001111101111111010111"
"11000111111000000001101100001000011110110010000001100001010100101011010010011010110011000010010010000010000010"
"10010100100001100011011000110010000110001101010110010001010101111001000101010010101100001100111100010011110111"
"10000101001010111110010000000001010000111010010001100010101101100001100110100010010011011110111111010010001000"
"01000110000111001011100001001100101110010000101010000101111100011100111101001111101110011011010110100000001011"
"10111101011101010110010010110000011011000010101111011010111010000111101101001110010110010110111001000111011011"
"11111110000100111110111110011110111100001100110111000001110100001001001001000001010100101100011010000101100011"
"00010011010110110000110011100110101001001100101001000111110000010110000000100010011011010101011100111000000100"
"11101011110110011001010101011001011010110111011111111010110000111010100100100110001111101011000010011100110110"
"10101001111011010101000111110000011110100011110110100001010101110111010101001110010001110101000101000101000001"
"01010010110001101011010110001100000111001001010000011000100110000110001000110010111111100101101010011110011101"
"10011110011000111100101110000101010101000110101101111010001000111001110100100001111110011111010101000110010101"
"00110010001111111011111000000100111001111001110101010001101110011000100100010110010111010011111000101100001011"
"11100010100010011000110110111010011001001001111011010010111000001111000011100100100100010011101011010001110010"
"01100101001101100001101100110000111111010010101000011010011000000111110100011000100001101010010110100110110110"
"01010001010000101001110011010110000101110001111010000101001011100100110100001001000001101000110101111110001010"
"01010000100100011000011000110110110111110100000010011110111001100000010011100100100101100010000010111111100101"
"10110110111000100000100010100000100001100001001110011101001000101000000110001110011000011101111100101000111101"
"01000011010010100100011000001000010001111011110001101010100110001111110100001101110100100001101101100010101101"
"11000010111011101011111111011110010000100010100101101101100100110101111000001101110010100000011100110101011000"
"01111011110010100000000010110111111110101010100011000010011100000110111110000000010000000000000000";

int main()
{
	FILE* fp = fopen("C:\\Users\\梦凡2.lenovo-PC\\Desktop\\hzk16.txt","wb");
	unsigned int i=0;
	unsigned int res;
	int j=0;

	while(*(p+j)!= '\0')
	{

		i = i << 1;

		i+= *(p+j) - '0';


	//	cout<<(int)(*(p+j) - '0')<<"======"<<endl;

		j++;
		if(j%32 ==0)
		{
			cout<< (unsigned int)i<<"===="<<j<<endl;

			res= htonl(i);

		//	res = (i & 0xff00) >> 4;
		//	res  =  res + ((i & 0x00ff) << 4);

			//cout<<sizeof(unsigned short)<<endl;

			cout<< (unsigned int)res<<"---"<<endl;

			fwrite((void*)&res,4,1,fp);
			i=0;
		}
	}
	fclose(fp);
    return 0;
}

你可能感兴趣的:(C++,c,VC)