首页 > 试题广场 >

Ws Cipher

[编程题]Ws Cipher
  • 热度指数:2725 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
Weird Wally's Wireless Widgets, Inc. manufactures an eclectic assortment of small, wireless, network capable devices, ranging from dog collars, to pencils, to fishing bobbers. All these devices have very small memories. Encryption algorithms like Rijndael, the candidate for the Advanced Encryption Standard (AES) are demonstrably secure but they don't fit in such a tiny memory. In order to provide some security for transmissions to and from the devices, WWWW uses the following algorithm, which you are to implement. Encrypting a message requires three integer keys, k1, k2, and k3. The letters [a-i] form one group, [j-r] a second group, and everything else ([s-z] and underscore) the third group. Within each group the letters are rotated left by ki positions in the message. Each group is rotated independently of the other two. Decrypting the message means doing a right rotation by ki positions within each group. Consider the message the_quick_brown_fox encrypted with ki values of 2, 3 and 1. The encrypted string is _icuo_bfnwhoq_kxert. The figure below shows the decrypting right rotations for one character in each of the three character groups.
Looking at all the letters in the group [a-i] we see {i,c,b,f,h,e} appear at positions {2,3,7,8,11,17} within the encrypted message. After a right rotation of k1=2, these positions contain the letters {h,e,i,c,b,f}. The table below shows the intermediate strings that come from doing all the rotations in the first group, then all rotations in the second group, then all the rotations in the third group. Rotating letters in one group will not change any letters in any of the other groups.
All input strings contain only lowercase letters and underscores(_). Each string will be at most 80 characters long. The ki are all positive integers in the range 1-100.

输入描述:
Input consists of information for one or more encrypted messages. Each problem begins with one line containing k1, k2, and k3 followed by a line containing the encrypted message. The end of the input is signalled by a line with all key values of 0.


输出描述:
For each encrypted message, the output is a single line containing the decrypted string.
示例1

输入

2 3 1 _icuo_bfnwhoq_kxert 1 1 1 bcalmkyzx 3 7 4 wcb_mxfep_dorul_eov_qtkrhe_ozany_dgtoh_u_eji 2 4 3 cjvdksaltbmu 0 0 0

输出

the_quick_brown_fox abcklmxyz the_quick_brown_fox_jumped_over_the_lazy_dog ajsbktcludmv
头像 健康快乐最重要
发表于 2020-03-03 12:02:00
可能有很多人因为这个题看不懂而望而却步了,这个题是真的长,英文是真的难看,但是算法确非常简单,就是字符串的转动操作。翻译:Weird Wally's Wireless Widgets, Inc. manufactures an eclectic assortment of small, wirele 展开全文
头像 lihuan269
发表于 2023-02-10 01:20:50
这题的难度完全在于英文。 “Encrypting a message requires three integer keys”这句话之前的所有句子都是废话,完全可以跳过。 后面的句子没有什么生词,结合样例可以理解它的移动规则。 另外测试用例错,整一个大无语,答案连下划线个数都变少了,害我认真又 展开全文
头像 886rtxz
发表于 2023-08-03 15:03:01
#include <iostream> #include <vector> using namespace std; // 直接模拟 string myreverse(string s, int k) { if (k > s.length()) 展开全文
头像 宁静的冬日
发表于 2022-03-07 09:23:40
C++ 有一组测试样例是错的,可以在自己的代码里加上如下片段: if (k1 == 28 && k2 == 15 && k3 == 74&&s == "nobhyeiuwnr_l___yptwsobmfzimu_hzgjw_bqzx") { 展开全文
头像 不会敲代码的张同学
发表于 2025-03-02 22:52:15
#include <iostream> #include <vector> using namespace std; int main() { int k1, k2, k3; string str = "", tempStr = &quo 展开全文

问题信息

难度:
20条回答 4556浏览

热门推荐

通过挑战的用户

查看代码
Ws Cipher