URI Online Judge | 1024
Encryption
By Neilor Tonin, URI Brazil
Timelimit: 1
You have been asked to build a simple encryption program. This program should be able to send coded messages without someone been able to read them. The process is very simple. It is divided into two parts.
First, each uppercase or lowercase letter must be shifted three positions to the right, according to the ASCII table: letter 'a' should become letter 'd', letter 'y' must become the character '|' and so on. Second, each line must be reversed. After being reversed, all characters from the half on (truncated) must be moved one position to the left in ASCII. In this case, 'b' becomes 'a' and 'a' becomes '`'.
For example, if the resulting word of the first part is "tesla", the letters "sla" should be moved one position to the left. However, if the resulting word of the first part is "t#$A", the letters "$A" are to be displaced.
First, each uppercase or lowercase letter must be shifted three positions to the right, according to the ASCII table: letter 'a' should become letter 'd', letter 'y' must become the character '|' and so on. Second, each line must be reversed. After being reversed, all characters from the half on (truncated) must be moved one position to the left in ASCII. In this case, 'b' becomes 'a' and 'a' becomes '`'.
For example, if the resulting word of the first part is "tesla", the letters "sla" should be moved one position to the left. However, if the resulting word of the first part is "t#$A", the letters "$A" are to be displaced.
Input
The input contains a number of cases of test. The first line of each case of test contains an integer N (1 ≤ N ≤ 1 * 10⁴), indicating the number of lines the problem should encrypt. The following N lines contain M characters each M (1 ≤ M ≤ 1 * 10³).
Output
For each input, you must present the encrypted message.
Input Sample | Output Sample |
4 Texto #3 abcABC1 vxpdylY .ph vv.xwfxo.fd | 3# rvzgV 1FECedc ks. \n{frzx gi.r{hyz-xx |
URI solution 1024 Encryption in C++ language
#include <iostream>
#include <algorithm>
#include <vector>
using
namespace
std;
int
main()
{
int
n, size;
string s;
cin >> n;
for
(
int
i = 0; i <= n; ++i)
{
getline(cin, s);
if
(i == 0)
continue
;
size = s.length();
vector<
char
> v(size);
for
(
int
j = 0; j < size; ++j){v[j] = s[j];}
for
(
int
j = 0; j < size; ++j)
{
if
((v[j] >=
'a'
&& v[j] <=
'z'
) || (v[j] >=
'A'
&& v[j] <=
'Z'
))
v[j] = v[j] + 3;
}
reverse(v.begin(), v.begin() + size);
for
(
int
j = (size/2); j < size; ++j)
{
//if(v[j] != ' ')
v[j] = v[j] - 1;
}
for
(
int
j = 0; j < (size/2); ++j){cout << v[j];}
for
(
int
j = (size/2); j < size; ++j){
//if(v[j] != ' ')
cout << v[j];
}
cout << endl;
}
return
0;
}
To Download URI 1024 Encryption in C++ language Click here
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks