`
bcyy
  • 浏览: 1830802 次
文章分类
社区版块
存档分类
最新评论

Timus 1712. Cipher Grille 题解

 
阅读更多

Our program committee uses different tools for problem development: a mailing list, a version control system, an administration system of theTimus Online Judgewebsite, and many others. Chairman of the program committee must constantly keep the passwords for these systems in his head. Of course, the passwords must be kept secret from the contestants, otherwise the problems may become known to them before the contest starts.
Not trusting his memory, the chairman wants to write down one of the passwords in a ciphered form. To do this, he plans to use a cipher grille he read about in one entertaining book.
A cipher grille is a 4 × 4 paper square in which four windows are cut out. Putting the grille on a paper sheet of the same size, the chairman writes down the first four symbols of his password in the windows (see fig. below). After that the chairman turns the grille clockwise by 90 degrees. The symbols written earlier become hidden under the grille and clean paper appears in the windows. He writes down the next four symbols of the password in the windows and again turns the grille by 90 degrees. Then he writes down the following four symbols and turns the grille once more. After that he writes down the last four symbols of the password. Now, without the same cipher grille, it is very difficult to restore the password from the resulting square with 16 symbols. Thus, the chairman is sure that no contestant will get access to the problems too early.
Problem illustration
Assume that you obtained the grille used by the chairman and the resulting square with 16 symbols. Your task is to recover the chairman's password.

Input

The first four lines contain the chairman's cipher grille. The window in it is denoted by the symbol “X” and the paper is denoted by “.”. The position of this grille corresponds to the position from which the chairman starts writing down his password. It is guaranteed that the grille is correct, which means that in the process of ciphering only empty cells appear in the windows. It is also known that the grille is connected, i.e. it is a single piece of paper.
The next four lines contain the square with the ciphered password. All the symbols in the square are lowercase or uppercase Latin letters.

Output

Output the password of the chairman of the program committee as a string consisting of 16 symbols.

Sample

input output
....
X..X
.X..
...X
Pwoo
Khaa
smrs
odbk
KamkohobPassword


很有意思的一个加密题目。

加密方法:就是弄一个加密版,然后弄个纸 方块,这个纸方块中间开了特定的4个空,先贴在加密版上,写下4个字母,然后顺时针选择90度,再写下4个字母,继续选择2次,写下16个字母,就是最后的密码了。

现在写个解密算法。

考的知识点就是:旋转数组的问题。

#include <string>
#include <vector>
#include <iostream>
using namespace std;

static const int CI_NUM = 4;

void RotateCipher(vector<string> &cipherGrill)
{
	for (int i = 0; i < CI_NUM; i++)
	{
		for (int j = i, k = CI_NUM - i - 1; k > i; j++, k--)
		{
			char c = cipherGrill[i][j];
			cipherGrill[i][j] = cipherGrill[k][i];
			cipherGrill[k][i] = cipherGrill[CI_NUM-i-1][k];
			cipherGrill[CI_NUM-i-1][k] = cipherGrill[j][CI_NUM-i-1];
			cipherGrill[j][CI_NUM-i-1] = c;
		}
	}
}

void CipherGrille1712()
{
	vector<string> cipherGill(CI_NUM);
	vector<string> cipherBoard(CI_NUM);
	for (int i = 0; i < CI_NUM; i++)
	{
		cin>>cipherGill[i];
	}
	for (int i = 0; i < CI_NUM; i++)
	{
		cin>>cipherBoard[i];
	}
	string rs;
	for (int d = 0; d < CI_NUM; d++)
	{
		for (int i = 0; i < CI_NUM; i++)
		{
			for (int j = 0; j < CI_NUM; j++)
			{
				if ('X' == cipherGill[i][j]) rs.push_back(cipherBoard[i][j]);
			}
		}
		RotateCipher(cipherGill);
	}
	cout<<rs;
}

int main()
{
	CipherGrille1712();
	return 0;
}



分享到:
评论

相关推荐

    AES加密DEMO(javax.crypto.Cipher NET实现)

    AES加密的几张方法包括javax.crypto.Cipher 的net实现方式

    javax.crypto crypto.jar

    javax.crypto.Cipher; javax.crypto.KeyGenerator; javax.crypto.spec.SecretKeySpec等

    python3 报错cannot import name '_AES'

    1.from Crypto.Cipher import AES 报错:cannot import name '_AES' 2.下载附件的,把附件的文件替换到python安装目录下的对应位置

    Fundamentals.Cipher407

    Fundamentals.Cipher407

    Pet Translator_1.1_anti_anti.apk.cipher

    Pet Translator_1.1_anti_anti.apk.cipher

    query.with.cipher.column

    encryptRule: encryptors: aes_encryptor: type: aes props: aes.key.value: 123456abc tables: t_user: columns: pwd: cipherColumn: pwd encryptor: aes_encryptor ...query.with.cipher.column: false

    pycrypto-2.6.1-cp37-cp37m-win_amd64.whl

    raise NotImplementedError("Use module Crypto.Cipher.PKCS1_OAEP instead") NotImplementedError: Use module Crypto.Cipher.PKCS1_OAEP instead SOLUTION pip uninstall pycryptodome pip uninstall pycrypto ...

    python3 解决cannot import name '_AES'问题

    1.from Crypto.Cipher import AES 报错:cannot import name '_AES' 2.下载附件的,把附件的文件替换到python安装目录下的对应位置

    Android代码-Uninstall_Statics

    Uninstall_Statistics 统计 应用 自身被 卸载 Android statistics application is uninstalled 参考自这篇blog http://www.cnblogs.com/zealotrouge/p/3157126.html ...

    文件加密解密算法(Java源码)

    cipher.init(Cipher.ENCRYPT_MODE, key, sr); // 执行加密操作 bytes = cipher.doFinal(bytes); // 返回字节数组 return bytes; } /** * 设置key文件路径 * @param keyfile String */ public void ...

    打开android上 cipher 加密的db

    打开android上 cipher 加密的db, 用于查看微信数据库!

    Cipherlab编程平台FastCollect

    欣技盘点机 编程平台-FastCollect(版本:1.12.5) 不需要写一行代码,只需要简单地勾选,即可100%满足您的需要。 10分钟即可完成程序的编写。普通的C编程一般需要一两周的时间,而且维护很麻烦,当需求改变时往往...

    SM2、SM3、SM4国密算法软实现

    SM2、SM3、SM4国密算法软实现,已经通过国家标准预设定参数进行测试,可直接使用。

    sqlcipher查看数据库工具3.0.1

    sqlcipher 数据的查看工具 对应sqlcipher 3.0及以上 sqlcipher 2.x加密的不可以 需使用 http://download.csdn.net/detail/zhanghw0917/7931759

    bcprov加密库

    at javax.crypto.Cipher.getInstance(Cipher.java:656) at javax.crypto.Cipher.getInstance(Cipher.java:595) ... 12 more Caused by: java.util.jar.JarException: file:/opt/code/signal-Server-master/target...

    DES算法crypto++

    DES算法,用crypto++实现的例子

    AESEncrypt.zip

    QT5.6.3 编译可使用,可对文件进行AES的加密和解密,大于10K的文件暂时未测试,可以对中文进行加密和解密

    cipher.exe.mui

    cipher.exe

    jce(Java加密扩展)

    1、javax.crypto.Cipher 类提供加密和解密的功能,它构成了 Java Cryptography Extension (JCE) —— Java 加密扩展框架的核心。这些都是 Java JDK 原生的 API,不是第三方的。 2、Cipher 的 getInstance(String ...

    plexus-cipher-1.4.jar

    plexus-cipher-1.4.jar

Global site tag (gtag.js) - Google Analytics