TOJ 4224 Cryptologist

Cryptologist 分享至QQ空间 去爱问答提问或回答

Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
Total Submit: 57            Accepted: 23

Description

Mirko received a message from his friend Slavko. Slavko, being a world class cryptologist, likes to encrypt messages he sends to Mirko. This time, he decided to use One Time Pad encryption. OTP is impenetrable if used correctly, and Slavko knows this. He however, doesn't want Mirko to bang his head on an impossible task, so he sent a few hints along with his message.
Mirko knows that Slavkos original plaintext contained only small letters of the English alphabet ('a' - 'z'), full stop '.' and space ' ' (ASCII 3210). Also, he knows that Slavko used only digits '0' to '9' as his key. After much thought, he realized he can determine locations of all spaces and full stops in the plaintext. He now asked you to write a program that will do so automatically.
From his previous dealings with Slavko, Mirko knows how OTP encryption works. Let's look at a simple example. Suppose you want to encode the string "abc efg" using "0120123" as key.

First, you transform both the key and plaintext into hexadecimal numbers using ASCII encoding. Then you align them and preform XOR operation on each pair. The resulting sequence is the encrypted message.

Input

The first line of input contains one integer N (1 ≤ N ≤ 1000), number of characters in the encrypted message.
Next line contains N integers, written in hexadecimal, larger than or equal to 010 and smaller than or equal to 12710, the encrypted message.

Output

The first and only line of output should contain N characters, each representing one character in the plaintext. If the ith character of plaintext is a letter, the ith character of output should be a dash '-', if not, you should output a full stop '.'.

Sample Input

7
51 53 51 10 54 54 54

Sample Output

---.---

Source

TOJ

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <set>
using namespace std;

set<int> S;
int n;

void init() {
    S.clear();
    int tmp;
    char str[2] = {'.', ' '};
    for(int i = 0; i < 2; i++) {
        for(int j = '0'; j <= '9'; j++) {
            tmp = str[i]^j;
            S.insert(tmp);
        }
    }
}

int main() {
     init();
    int i, tmp;
    while(scanf("%d", &n) != EOF) {
        for(i = 1; i <= n; i++) {
            cin >> hex >> tmp; //十六进制考虑 A~F
            set<int>::iterator it;
            it = S.find(tmp);
            if(it == S.end()) {// find it;
                printf("-");
            }else {
                printf(".");
            }
        }
        printf("\n");
    }
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值