Timus 1404. Easy to Hack! 有一个密码问题

When Vito Maretti writes an important letter he encrypts it. His method is not very reliable but it’s enough to make any detective understand nothing in that letter. Sheriff doesn’t like such state
of affairs. He wants to hack the cipher of Vito Maretti and he promises to forget about all of your faults if you do that for him. Detectives will tell you what this cipher looks like.

Each word is enciphered separately. Assume an example that consists only of the small Latin letters.

At first step every letter is replaced with the corresponding number: a with 0b with 1c with 2,
..., z with 25.Then 5 is added to the first number, the first number is added to the second one, the second number – to the third one and so on. After that if some number exceeds 25 it is replaced with the residue of division
of this number by 26. And then those numbers are replaced back with the letters.

Let’s encipher the word secret.

Step 0.   s   e   c   r   e   t
Step 1.   18  4   2   17  4   19
Step 2.   23  27  29  46  50  69
Step 3.   23  1   3   20  24  17
Step 4.   x   b   d   u   y   r

We’ve got the word xbduyr.

Input

You are given an encrypted word of small Latin letters not longer than 100 characters.

Output

the original word.

Sample

input output
xbduyr
secret

原来简单的加密也不是什么难事。做了那么多加密题,我也可以随手写个加密器了。

本题就是一个字符串的操作, 考的是字符串和整形之间的转换操作:

本题注意:第一个字母小于f的时候,转换为整数就会小于5了。

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

void EasytoHack1404()
{
	string s;
	cin>>s;
	vector<int> tmp(s.size());
	for (int i = 0; i < s.size(); i++)
	{
		tmp[i] = s[i] - ‘a‘;
	}
	int t = tmp[0];
	tmp[0] -= 5;
	if (tmp[0] < 0) tmp[0] += 26;
	for (int i = 1; i < tmp.size(); i++)
	{
		int a = tmp[i];
		tmp[i] -= t;
		if (tmp[i] < 0) tmp[i] += 26;
		t = a;
	}
	for (int i = 0; i < tmp.size(); i++)
	{
		cout<<char(tmp[i]+‘a‘);
	}
}

Timus 1404. Easy to Hack! 有一个密码问题,码迷,mamicode.com

时间: 2024-07-30 03:25:48

Timus 1404. Easy to Hack! 有一个密码问题的相关文章

URAL 1404. Easy to Hack! (模拟)

space=1&num=1404">1404. Easy to Hack! Time limit: 1.0 second Memory limit: 64 MB When Vito Maretti writes an important letter he encrypts it. His method is not very reliable but it's enough to make any detective understand nothing in that lett

做了一个密码强度输入测试

<!doctype html> <html> <head> <meta charset="utf-8"> <title>密码强度输入测试</title> <style type="text/css"> .cont { margin-left:300px; margin-top:50px; border:solid 1px #ccc; width:520px; padding:20px

1Password:让一个密码记住所有密码

在这个信息大爆炸的时代,我们总有着各种各样的缘由,接触到各种各样的网站和爱屁屁,随之而来的,产生了大量的账号和密码. 每次新注册一个网站的时候,总会纠结一番:到底是新编一个密码呢?还是沿用之前的那一个密码呢?编个新密码明天就忘了,下次白想半天还得重新注册一次:用以前的密码呢,所有的号都是一个密码,简直就是坑. 微信扣扣等社交账号有掌握了我大量的信息,也不敢轻易授权登录. 对于日益庞大的密码队伍,每次需要用到的时候,只能随缘,能想起能找到最好,找不到也就只有扭扭屁股再来一次.总是在想有没有一个密码

Python练习题9(密码判断):请写一个密码安全性检查的代码代码: 首先判断密码的强度,如果结果是低或中则打印如何提升密码安全级别的提示,而高则直接退出

'''请写一个密码安全性检查的代码代码:首先判断密码的强度,如果结果是低或中则打印如何提升密码安全级别的提示,而高则直接退出 # 密码安全性检查代码## 低级密码要求:# 1. 密码由单纯的数字或字母组成# 2. 密码长度小于等于8位## 中级密码要求:# 1. 密码必须由数字.字母或特殊字符(仅限:[email protected]#$%^&*()_=-/,.?<>;:[]{}|\)任意两种组合# 2. 密码长度不能低于8位## 高级密码要求:# 1. 密码必须由数字.字母及特殊字符

每分钟变换一个密码的加密验证功能

越南项目需要引入用户管理的模块,需要有注册登录的功能,因为有来自政府部门的订单,所以对安全方面的要求比较高. 我在注册登录的功能中引入变换密码的加密概念. 用户注册加密过程:服务器拿到原始密码,使用SHA_1算法加密,再使用MD5加密,然后存入数据库. 用户登录加密验证过程:客户端拿到用户输入的密码,使用SHA_1算法加密,再使用MD5加密,将得到的密文加上时间戳,然后再按照之前方式加密一次,提交给服务器.服务器接收到密文之后,在数据库中查询出用户注册时的密文,给密文加上时间戳,再使用SHA_1

Golang实现一个密码生成器

小地鼠防止有人偷他的果实,在家里上了一把锁.这个锁怎么来的呢?请往下看.. package main import ( "flag" "fmt" "math/rand" "time" ) var ( length int charset string ) const ( NUmStr = "0123456789" CharStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde

用字符串处理函数中的比较函数strcmp做的一个密码登录验证

正确返回0 1大返回正数 2大返回负数  1,2表示输入字符串1和字符串2 根据ASCII码大小来判断 代码: 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 //字符串比较函数 根据ASCII码值的大小来比较 strcmp 6 //相等 返回0 1大返回正数 2大返回负数 1和2为要比较的两个字符串 7 char user[20] = { "mrsoft" }; //设置用户名字符串 8

Java学习:一个仿ATM机键盘做的密码输入

1.程序运行截图: 2.程序实现的功能 1)进入程序时,程序会询问你输入一个密码 2)进入键盘界面后,按下数字0-9可以输入一个字符,按取消按钮可以退出程序,重置按钮可以将上面的JPasswordField变为空,按下确定按钮,提示输入的密码是否正确 3.程序代码 import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Arrays;

使用jQuery开发一个带有密码强度检验的超酷注册页面

在今天的jQuery教程中,我们将介绍如何使用jQuery和其它相关的插件来生成一个漂亮的带有密码强度检验的注册页面,希望大家喜欢! 相关的插件和类库 complexify - 一个密码强度检验jQuery插件 justgage - 一个兼容性良好的仪表盘类库 主要功能 注册中包含一个密码强度检验组件,用户需要设置一定强度的密码才可以注册 密码强度使用仪表盘类库justgage来显示,不同的强度的密码将显示不同的颜色 密码强度符合要求后,显示注册按钮 代码说明 HTML: <div id="