《RUBY QUIZ - The Solitaire Cipher 》

本文介绍了一种基于纸牌游戏的手动加密方法,并详细解释了如何使用Ruby语言编写加密和解密程序。

本将开始一个漫长的翻译过程,初次翻译,翻译有误的地方,请指出……看的不明白的看原文。

 

本人将对RUBY QUIZ的一些测试进行翻译,并且对RUBY语言进行探讨和研究。

 

那么,现在就开始吧!朋友们!

 

The Solitaire Cipher

 

Cryptologist Bruce Schneier designed the hand cipher "Solitaire" for Neal Stephenson's book "Cryptonomicon". Created to be the first truly secure hand cipher, Solitaire requires only a deck of cards for the encryption and decryption of messages.

 

密码学家布鲁斯为尼尔史蒂芬森的著作“ Cryptonomicon ”设计手密码“纸牌游戏” 。创建的第一个真正安全的手密码,纸牌游戏,只需要一副纸牌为讯息加密和解密。

 

While it's true that Solitaire is easily completed by hand given ample time, using a computer is much quicker and easier. Because of that, Solitaire conversion routines are available in many languages, though I've not yet run across one in Ruby.

 

纸牌很容易完成的手给予充裕的时间,使用电脑是更快和更容易。由于这个原因,纸牌密码转换例程有许多语言可执行程序,但我已经没有遇到一个红宝石。

This week's quiz is to write a Ruby script that does the encryption and decryption of messages using the Solitaire cipher.

 

本周的比赛是写的Ruby脚本,利用纸牌密码写一个对信息加密和解密的程序。

 

Let's look at the steps of encrypting a message with Solitaire.

 

让我们来看看的用纸牌加密信息的步骤。

 

 

1. Discard any non A to Z characters, and uppercase all remaining letters. Split the message into five character groups, using Xs to pad the last group, if needed. If we begin with the message "Code in Ruby, live longer!", for example, we would now have:

 

1.丢弃任何非A到Z字,和所有其余的字母大写。分解信息分为五字母为一组,当不够时,用X来填充最后一组。如果我们开始用信息“Code in Ruby, live longer! ” ,例如,我们现在有:


          CODEI NRUBY LIVEL ONGER

 

2. Use Solitaire to generate a keystream letter for each letter in the message. This step is detailed below, but for the sake of example let's just say we get:

 

2.使用纸牌生成密钥信的每个字母的信息。这在一步下面详细列出,而是为了例子的原因让我们只想说我们得到:

 

DWJXH YRFDG TMSHP UURXJ

 

3. Convert the message from step 1 into numbers, A = 1, B = 2, etc:

3.转换第一个步骤的信息为号码, A = 1 ,B= 2 ,等等:

3 15 4 5 9 14 18 21 2 25 12 9 22 5 12 15 14 7 5 18

 

4. Convert the keystream letters from step 2 using the same method:

4.使用相同的方法转换第2步的密钥信:

4 23 10 24 8 25 18 6 4 7 20 13 19 8 16 21 21 18 24 10

 

5. 第五步:把第三步生成的数量加上第四步生成的数字,如果其大小大于26,那么就减去26,比如,加起来 6+10,那么就 16,如果 26+1,那么就等于27-26,即为1:

7 12 14 3 17 13 10 1 6 6 6 22 15 13 2 10 9 25 3 2

 

6. Convert the numbers from step 5 back to letters:

6.把步骤5的算出来的信息转换成字母:

GLNCQ MJAFF FVOMB JIYCB

 

 

That took a while to break down, but it's really a very simple process. Decrypting with Solitaire is even easier, so let's look at those steps now. We'll work backwards with our example now, decrypting "GLNCQ MJAFF FVOMB JIYCB".

 

而且在这方面花了一段时间来打破,但它上是一个非常简单的过程。用纸牌算法解密更加容易,所以让我们看看现在这些步骤。现在我们将继续用我们的实例,解密“ GLNCQ MJAFF FVOMB JIYCB ” 。

 

 

1. Use Solitaire to generate a keystream letter for each letter in the message to be decoded. Again, I detail this process below, but sender and receiver use the same key and will get the same letters:

1.使用纸牌算法生成密钥信的每个字母的信息进行解码。同样,我在下面详细说明这一过程,但发送和接收使用相同的钥匙,并会得到相同的信息:

DWJXH YRFDG TMSHP UURXJ

2. Convert the message to be decoded to numbers:

2.把信息转换,译码为数字。

7 12 14 3 17 13 10 1 6 6 6 22 15 13 2 10 9 25 3 2

 

3. Convert the keystream letters from step 1 to numbers:

3.转换第1步的字幕信息为数字:

4 23 10 24 8 25 18 6 4 7 20 13 19 8 16 21 21 18 24 10

 

4. Subtract the keystream numbers from step 3 from the message numbers from step 2. If the message number is less than or equal to the keystream number, add 26 to the message number before subtracting. For example, 22 - 1 = 21 as expected, but 1 - 22 = 5 (27 - 22):

4. 从信息中第二步的得出的数字减第三步的的出的数字,如果小于等于0,就用26减去得出的结果:

3 15 4 5 9 14 18 21 2 25 12 9 22 5 12 15 14 7 5 18

 

5.再次将数字串换为字幕:

 CODEI NRUBY LIVEL ONGER

 

 

Transforming messages is that simple. Finally, let's look at the missing piece of the puzzle, generating the keystream letters.

 

转换信息就是这么简单。最后,让我们来看看这个地方的困难所在,生成密钥字母。

 

 

1. Key the deck. This is the critical step in the actual operation of the cipher and the heart of it's security. There are many methods to go about this, such as shuffling a deck and then arranging the receiving deck in the same order or tracking a bridge column in the paper and using that to order the cards. Because we want to be able to test our answers though, we'll use an unkeyed deck, cards in order of value. That is, from top to bottom, we'll always start with the deck:

 

1.关 键的层次。在实际运作的密码和安全核心里这是关键的一步。有许多方法去了解这一点,如移动纸牌,然后安排接收纸牌在同一命令或跟踪的桥牌列在一副里,并使 用它排序卡片。因为我们希望能够检验我们的答案不过,我们会使用一个unkeyed卡片,有序的卡片顺序。也就是说,从上到下,我们将始终在用纸牌来做:

Ace of Clubs
...to...
King of Clubs
Ace of Diamonds
...to...
King of Diamonds
Ace of Hearts
...to...
King of Hearts
Ace of Spades
...to...
King of Spades
"A" Joker
"B" Joker

2. Move the A joker down one card. If the joker is at the bottom of the deck, move it to just below the first card. (Consider the deck to be circular.) The first time we do this, the deck will go from:
2. 移动A大王向下一卡片。如果大王在一副牌的底部,将它移到为第一张牌。 (考虑一副牌是循环。 )第一次,我们做到这,一副牌将往前:

1 2 3 ... 52 A B

To:

1 2 3 ... 52 B A

 

3. Move the B joker down two cards. If the joker is the bottom card, move it just below the second card. If the joker is the just above the bottom card, move it below the top card. (Again, consider the deck to be circular.) This changes our example deck to:

3.移动B大王向下一卡片。如果大王在一副牌的底部,将它移到为第二张牌。如果大王高于底部牌,将其移动低端牌。 (再次,考虑一副牌是循环。 )这改变我们举例为:

 

1 B 2 3 4 ... 52 A

 

4. Perform a triple cut around the two jokers. All cards above the top joker move to below the bottom joker and vice versa. The jokers and the cards between them do not move. This gives us:

4 。围绕两个jokers执行三次 。所有大王以上牌移动到下面大王的底部,反之亦然。大王和其他牌之间不会移动。这使我们:
B 2 3 4 ... 52 A 1

5. Perform a count cut using the value of the bottom card. Cut the bottom card's value in cards off the top of the deck and reinsert them just above the bottom card. This changes our deck to:

5 。执行数减少底部牌的值。切花底部卡的价值在起飞卡顶部的甲板和重新插入略高于底部卡。这种变化我们甲板到:

2 3 4 ... 52 A B 1 (the 1 tells us to move just the B)

 

6. Find the output letter. Convert the top card to it's value and count down that many cards from the top of the deck, with the top card itself being card number one. Look at the card immediately after your count and convert it to a letter. This is the next letter in the keystream. If the output card is a joker, no letter is generated this sequence. This step does not alter the deck. For our example, the output letter is:

6 。寻找输出信。转换顶端卡给它的价值和数量下降,许多卡顶部的甲板上,与顶端信用卡本身正在信用卡号码1 。看后您的信用卡数量和将其转换为信。这是下一个字母密钥。如果输出卡是一种滑稽,不信是产生这一序列。这一步骤不会改变原来的甲板上。对于我们的例子 中,输出信是:

D (the 2 tells us to count down to the 4, which is a D)

 

7. Return to step 2, if more letters are needed.

For the sake of testing, the first ten output letters for an unkeyed deck are:

7 。返回到步骤2中,如果有更多的信件是必要的。
为了试验,产量前十位的字母unkeyed甲板是:

D (4) W (49) J (10) Skip Joker (53) X (24) H (8)
Y (51) R (44) F (6) D (4) G (33)

 

That's all there is to Solitaire, finally. It's really longer to explain than it is to code up.

Solutions to this quiz should accept a message as a command line argument and encrypt or decrypt is as needed. It should be easy to tell which is needed by the pattern of the message, but you can use a switch if you prefer.

All the examples for this quiz assume an unkeyed deck, but your script can provide a way to key the deck, if desired. (A real script would require this, of course.)

Here's a couple of messages to test your work with. You'll know when you have them right:

这是所有有纸牌,最后。这真的不再来解释而不是代码了。

解决这一测验应该接受邮件作为命令行参数,并进行加密或解密是必要的。应该可以很容易地分辨出所需要的是模式的消息,但您可以使用一个开关,如果你喜欢。

所有的例子本测验承担unkeyed甲板,但您的脚本可以提供一种关键的甲板,如果想要的。 (一个真正的脚本将需要这一点,当然。 )

这里的一对夫妇的消息来测试您的工作。你知道当你有他们的权利:

CLEPK HHNIY CFPWH FDFEH

ABVAW LWZSY OORYK DUPVH

 


中国乡村创新创业指数,由浙江大学卡特农业与农村经济发展研究院与企业研究团队携手打造,是一项全面评估中国乡村地区创新与创业活力的权威指标体系。该指数体系由“乡村创新”与“乡村创业”两大核心一级指标构成,深度剖析了乡村发展的内在动力与外在表现。 在“乡村创新”维度下,进一步细化为技术创新、品牌创新、绿色创新、数字创新四个二级指标,全面覆盖了乡村在科技应用、品牌建设、环境保护及数字化转型等方面的创新能力。而“乡村创业”则聚焦于农业及相关产业创业、农民合作社创业、家庭农场创业三大板块,展现了乡村经济多元化发展的创业生态。 这七大二级指标进一步拆解为21个三级指标,确保了评价的全面性和精准性。指数自2014年起至2021年连续发布,不仅展现了近年来中国乡村创新创业的演进轨迹,还通过横纵向对比,为研究人员、投资者及社会各界提供了参考依据,助力乡村振兴战略深入实施。 引用规范:阮建青、杨奇明、叶武威、张雨薇,2023,《中国乡村创新创业指数报告(2023)》,浙大卡特-企研乡村产业研究团队工作论文 一、数据介绍 数据名称:中国省、市、县级乡村创新创业指数 数据年份:2014-2021年 样本数量:1万7+条 数据格式:面板数据 二、指标说明 共计10个指标:省份代码、省份名称、地市代码、地市名称、县市代码、县市名称、年份、乡村创业指数、乡村创新指数、总指数 三、数据文件 中国省、市、县级乡村创新创业指数(2014-2021年).xlsx
内容概要:本文围绕分布式传感器网络中的LEACH聚类算法展开深入研究,重点评估其在能量消耗方面的性能表现,并通过Matlab代码实现完整的仿真系统。文中系统阐述了LEACH协议的核心工作机制,包括基于概率的簇头选举机制、数据融合与多跳传输策略,详细分析了其在延长网络生命周期、降低能耗方面的优势与存在的局限性。研究构建了标准化的无线传感器网络模型,通过仿真实验对比不同节点分布、初始能量配置和轮询机制下的能量耗尽过程,定量评估网络存活时间、死亡节点增长曲线和剩余能量分布等关键指标,进而提出针对性的优化方向以提升算法的能量效率与系统稳定性。此外,文档还关联了智能优化算法、WSN覆盖优化、路由优化等多项关键技术,体现了LEACH协议在物联网、环境监测和智能感知等领域的广泛应用价值。; 适合人群:具备一定Matlab编程基础和无线通信基础知识,从事无线传感器网络、物联网工程、通信系统设计及相关方向研究的科研人员、高校研究生及工程技术开发者。; 使用场景及目标:①用于教学与科研中对LEACH协议运行机制的理解与仿真实践;②为优化无线传感器网络的能量管理策略和拓扑控制提供理论依据与实验平台;③作为进一步研究低功耗路由协议、簇头优化算法及大规模WSN部署的基础工具; 阅读建议:建议读者结合提供的Matlab代码进行实际运行与参数调优,深入理解每一轮迭代中簇头选择、数据聚合和能量更新的实现细节,同时可参考文中提及的Leach协议优化方向拓展研究思路,提升系统级仿真与算法创新能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值