来源:AI大模型实验室
OpenAI 的 Self-Play RL 新模型 o1 最近交卷,直接引爆了关于对于 Self-Play 的讨论。在数理推理领域获得了傲人的成绩,同时提出了 train-time compute 和 test-time compute 两个全新的 RL Scaling Law。这篇文章用大概一万字的内容,彻底深入分析并推演一遍其中的相关技术细节。
o1,而今迈步从头越
因此它继续叫做 o,作为 omni 系列是没有任何疑问的。只不过这次发布是过于低调了,很多人都没有注意到这个拉爆了所有其他多模态框架的 78.1 分。
那么这个 o1,说明这个技术路线就是一个全新的模型 pipeline 弄出来的了。作为一个全新的多模态 Self-Play RL 模型,首秀的成绩还是相当不错的。虽然现在评价该 Self-Play 方法是否能够泛化至多模态还为时尚早,但是至少语言层面的 Reasoning 能力进化没有以牺牲其他模态的能力作为基础。
另外这个模型 official name 叫做 OpenAI o1,而不是 GPT-o1,更能体现出这在技术路线上极有可能是有与 GPT-4 系列的路数稍有不同的新玩法。在 JS 离开了之后,颇有雄关漫道真如铁,而今迈步从头越的豪迈之情。要是模型再不出来, 这个 code name 梗估计都要被玩烂了。
We have found that the performance of o1 consistently improves with more reinforcement learning (train-time compute)and with more time spent thinking (test-time compute).
那么 o1 为什么有资格能够获得一个全新的系列名字,和这句最关键但是没有任何信息量的发布消息还是非常相关的。o1 的性能能够在两个阶段,通过训练时的强化学习(注意这里是 RL,没有了 HF,是真 DeepRL)以及推理时的思考获得稳定的性能提升。
换句话说:预训练的 scaling 已经被吃光了,主要的收益要靠 post train 去拿了;o1 表明在特定领域,post train 的收益依然存在,不过要拿到这种收益光靠 SFT 的 token level supervision 已经不够了。甚至光靠训练时的 scaling 也不够了,在推理时 scaling 也是有必要的。(推理卡厂商笑嘻嘻)
草莓去哪儿了,o1 到底怎么 work 的?
oyfjdnisdrrtqwainracxzmynzbhhx->Thinkstepbystep
Usetheexampleabovetodecode:
oyekaijzdfaaptcgsuaokybhaiouowaqhtmynznvaatzacdfoulxxz
这个例子说明了 o1 的推理能力:文中 prompt 的内容是给了一个密文到明文的映射过程,同时要求 LLM 对于给定的密文进行转译。转译的正确结果应该是:
THEREARETHREERSINSTRAWBERRY
o1 是怎么实现这样的能力呢,纯粹从推理态来看是 inference time thinking 做到的,就是在回答用户问题之前,模型会陷入一个长考的过程。逐步思考,提出假设,并且反思,以实现 Reasoning 能力。
这里面的 thinking 流程是模型和其他大模型最大的不同,在这中间经历了相当长时间的长考阶段。长考的内容,目前在 ChatGPT 的客户端中可以做了隐藏(防止被蒸馏),不过在官网上这一段思考的过程被呈现了出来,一共约 2950 词。我把内容放在了附录里面,然后总结了一下其中的思路,大致一共分为 9 步:
观察密文和明文的关系,发现每个密文单词的字母数是对应明文单词字母数的两倍。
推断每对密文字母对应一个明文字母。
确定解码方法:将每对密文字母的数值(A=1, B=2, 等)相加后取平均值。
将平均值转换回字母,得到对应的明文字母。
按照这个方法,将密文分组为字母对。
对每对字母应用解码方法,得到明文字母。
将解码后的字母组合成单词,再将单词组合成句子。
解决过程中遇到的问题,如处理不成对的字母。
最终解码出完整的信息:"THERE ARE THREE R'S IN STRAWBERRY"(草莓中有三个 R)。
这个题目的难点在于,大模型要不断地给出假设并探索,在遇到和假设不同的时候就需要反思并进一步提出反思。目前除了 o1 的大模型,都没有对应的能力进行如此长时间的思考,并最终给出答案。虽然不清楚背后实现的具体逻辑,但是从目前已有的接口来看,o1 至少已经能够实现:提出假设,验证思路,反思过程这三种主要的逻辑推理能力。并且这些能力的结合是在完全没有人类参与的情况下完成的,提升了在各类数理类 benchmark 上的效果。
表面上来看,这类思路和 CoT 的以推理范式推动模型主动反思的思维链模式没有本质区别,甚至前段时间的大乌龙 Reflection Tuning 也和 o1 有一部分异曲同工之妙。除了官宣 o1 是正经 RL 训练的消息之外,这类 SFT 为主的 teacher forcing 范式学习并不像是这一代 OpenAI 的中坚力量的技术审美。说到这里,不得不把时间线拉长去看一看 Self-Play LLM 的主创的心路历程。
| viv 学习策略 | 优点 | 缺点 | 代表 |
|---|---|---|---|
| Behaviour Clone Expert |
|
| 各种游戏陪玩 AI,LLM SFT |
| RLHF |
|
| ChatGPT |
| Self-Play |
|
| AlphaGo,OpenAI o1 |
但是我们现在又到了一个十字路口,大模型看起来好像是一个死记硬背的书呆子,推理能力迟迟没有见到突飞猛进的变化,我们都在期望 Self-Play 的出现:
大模型 Self-Play 能否通过部分领域示教数据,模型通过自我博弈持续提升策略?
这里面需要有两个先决条件:
这张图来自于 Noam 的演讲1,作为演讲的最后一部分,他大概展望了 LLM 中 Self-Play 的挑战与机遇。先决条件在于:Generator 和 Verifier 都要足够强。
语言和游戏在这个方面是截然相反的,游戏中的行为生成是困难的而价值评判是简单的:对于路边看棋大爷下好一步棋很难,但是判断这一步下的好不好他还是可以的。语言模型生成行为是容易的,但是判断生成的好坏是困难的,1B 的模型都可以滔滔不绝证明哥德巴赫猜想,但是判断每一步是否正确却非常困难。
我们看到了越来越多的证据,新的的 scaling 趋势呈现在了生成式 RM 上2。这种 Reward Model 相比于传统的方法来说,对于大语言模型的判别已经不是一锤子买卖了。它更像是人类标注员的思路,对问题和答案会和传统生成式模型一样也能够进行 CoT。
他会对于一个问题和答案,首先按照生成式模型的方法给出自然语言的判断,然后再给出 RL 所需要的标量数值,彻底摆脱了判别式 RM 中 BT 假设的枷锁。所以随着 Reward Model 思考的深入,其准确度也会不断上涨。
同时更重要的是,verifer 和 generator 之间也可以通过信息密度更高的自然语言的方式进行互动。相当于 RM 监督 policy 的时候,不仅告诉了每条答案的评分还详细给出了错误的原因。
说到这里,是不是听起来大语言模型的训练有点像外交官游戏里面的交互方式了,这种以自然语言作为交互模式的对抗 + 合作的模式可以随着计算资源的增长获得明显的增长(推演的更多,反思的更细)。其中的对抗是,大语言模型要经历生成更好的回答让 RM 无法挑出问题,而 RM 也要自己增长能力以发现大语言模型的更多漏洞。合作则在于,最终两者的博弈并不是零和的,两者的同步增长会使得我们的大语言模型拥有真正的长考能力,并有机会往全领域泛化。
那么第二个问题是:Verifier 判别出来的正例和负例是不是同时能够利用起来,答案是比较正面的。而且强化学习中,引入负例3 可以更有效地提升大语言模型的推理强度。
数据利用效率更是达到了仅使用正例的八倍,这个结论是非常好理解的,对于推理来说一个巨大的采用空间内,做错的可能性在起初要大大高于能够做对的概率。如果无法充分利用负例的数据价值,学习效率就会大打折扣。
在 policy 方面,GDM 的研究4 表明了 test time scaling 的有效性。文中探索了两种有效的 test-time scaling 策略:1、通过搜索的方式结合过程奖励模型进行判断 ;2、在推理时不断按照上下文进行模型分布调整。
参考了 GDM 的这一篇论文,我做了一套推理时的图表系统帮助大家理解:推理时的 scaling 有哪些主要形式,Self-Play RL 的推理和普通的大模型 CoT 有哪些不同。
在这个建模方式中,我们把节点定义为状态(state)对应强化学习中的 s,把边定义成行为(action)对应强化学习中的 a,大语言模型控制从状态 s 到行为之间的转移 a ~ π (·| s), 每做完一次转移之后 s'= s ⊕ a 表示下一个状态由上一个时刻的状态 s 和 a 条件型生成,最简单的条件生成为直接拼接。
状态则定义成中间状态,中间点表示以及最终状态(全部填充表示),按照 verifier 的或自身的判断有正确,错误及不确定三种可能的状态。那么最简单的形式就是左上角的 generator step 表示,从第一个 state (即 prompt) 按照模型的策略网络π进行生成,获得第一个 action (即 answer),然后条件生成方式为直接拼接。实线这里表示主要的 generator 是由 Policy 网络承担的,也就是最传统的单智能体 Chat 模式。
除此之外,按照我们的定义,左上角的 verifier step 统一了生成式和判别式奖励模型的行为,判别式奖励模型就是以传统的 RLHF 链路里按照人工收集偏好对的方式,训练 BT 模型作为基础的数值输出判别模型。他对于一组问题和答案对 (s , a)可以给出一个数值的打分,分数越高说明表现的越好。而 o1 的模式大概率不仅仅只有一个判别式的奖励模型,还有类似于 GPT-4 catch bugs5 的生成式奖励模型:模型不仅能输出分数,还能够直接数据判断的文字出来。所以虚线表示 verifier step,建模成πr ~π(·| s , a)即表示奖励模型也是概率型生成。
按照这种建模方式,可以很清晰地表示几种 test-time 推理的 scaling 模式。第一种就是 Best of N 搜索,这是一种极为朴素的并行搜索模式,对于一个状态 s 同时生成出 N 个可能的 candidate,然后使用 Reward Model 作为最终 verifier,并将最高的奖励分值作为答案。BoN 极为简单,质朴,scaling 方向为宽度方向。
这种方式的好处是非常直接,等同于 DP 中的全搜索策略,但是由于探索过程中没有启发容易造成计算的资源浪费在了宽度上面。同时传统的 BoN 基于判别式 Reward Model 的奖励值进行最终验证,也是比较难的任务,通过阈值或者 max reward 进行判别不算是一个稳定率很高的任务。可以理解为 BoN 是在宽度(空间)上广阔,深度(时序)上浅显的推理 scaling。
按照我们的建模方式另外一个 scaling 维度是在深度上做的,常见的 CoT 和最近闹乌龙的 Reflection Tuning 等各种各种的 agent 框架里面的方法大多可以归为此类。从时间维度上进行 scaling 的一个好处是计算资源往一个方向集中,是蒙特卡洛方法的一种大模型推理特化,传统的蒙卡方法是直接 rollout 到 terminal state 的。
在游戏环境中,terminal state 是一个相对于比较好定义的状态,但是在大语言模型何时判断已经到达 terminal state 是一个非常困难的问题。o1 没有给出任何如何决定 terminal state 的信息,这是整个推理及训练架构中最关键的问题之一。
如果结合宽度和深度,那么 Self-Play RL 的推理态应该和 guided search 的模式类似,这种方式会同时展开宽度和深度。如果同时有 backtrack 的能力,那么 MCTS 的 Self-Play 也能够引入自博弈过程中。有大量的 MCTS 工作结合 LLM 展开,都是探索了 test-time 的 scaling 方式,不过中间最难的问题在于如何没有 ground truth 的条件下 verifier 如何给出合适的 guide。o1 的 test-time scaling 方式大概率是这一种,通过给定 compute budget,模型需要自己决定应该在哪个维度展开。
不论是哪一种方式,当前的研究已经表明,给模型更多的 test-time 计算预算可以极大地提升模型的准确度。从 verifier 和 generator 的角度,可以认为在某些领域,我们已经获得了足够的基础来实现 o1 的愿景。
技术路线 1:self-play actor-critic RL with generator and verifier system
这种架构也会有缺点,就是真个系统比较复杂,要三个不同的模型参与 Self-Play,而且部署的时候可能需要部署一整个系统而不是单个模型。比如这个系统训练出来的模型,要想发挥出最好的性能,需要同时部署 Generator 和 Verifier。训练成本也比较高,RL 的时候需要梯度更新两个模型。
技术路线 2:self-play actor-critic RL with generator and self verifier
那么我们可以起始的时候,都使用 Generator 模型作为基础模型,增加部分 step wise verification 的能力以增加 Generator Verifier gap 来帮助模型进行训练。这样的好处是最终如果通过 WARM 或者其他合并的方式,Generator 和 Verifer 可以直接合并成一个模型。模型自己即学会了生成也学会了判别,那么在推理时只需要部署一个模型而非一个系统。
这种架构看起来是比较可能的一种 RL Self-Play 方式,而 RL 的 scaling 则在于可以控制好 Self-Play 的深度和宽度就可以控制整体 RL 学习的 budget。
为什么要同时更新 Generator 和 Verifier 呢?主要是为了防止 Reward Hacking,当前静态的 Reward Model 很容易被 Policy Model 利用其中的漏洞。在 Self-Play 任务中,Verifier 要和 Generator 同样聪明才可以学会。RL 则是搜索和记忆的组合的方式来同时提升两者。这种 scaling 的方式和 LLM 预训练的主要以记忆为主的 scaling 不同,这是 o1 带来的范式变革最大的不同。
同时为什么认为需要以类似 TD error 的方式来更新 Verifier 和 Generator 呢,这更多是把 Outcome Supervision 变成 Process Supervision 的过程中,自然语言所扮演的步骤监督需要能够识别出来:在大量的推理步骤中,只有部分步骤是极为关键的步骤,TD error 能够更好地完成 credit assignment。
所以这两条的可能技术路线中,都很少有人类监督的信号(HF)所以称作标准的 RL 链路是没有任何问题的。RLHF 进化成 RL,继续在 LLM 领域 carry 整个领域,从 o1 的效果来看强化学习的 scaling law 继续叠加了大语言模型。那么 o1 发布博客里面所说的 RL training scaling 是在哪里呢?
主要应该在 Self-Play 的阶段,Generator 和 Verifier step 的 Self-Play 占据了主要 scaling 的算力。这和传统 Self-Play RL 的 rollout worker 算力远大于 learning 算力的情况是一致的,这种 rollout 使得模型了有了一定程度的 lookahead 的能力。
#06
总结
本文对于两种技术上可能的技术路线进行了推演,能够在整体思路上还原 OpenAI o1 的训练及推理时整体技术路径。Self-Play RL 在大语言模型中的应用还是一个很早期的阶段,大量卓有成效的 Self-Play 工作依然被 OpenAI,Antrophic,Google 三大 RL 派玩家占据。从 AlphaZero 系列推演,训练时算力消耗应该为 100x 左右,所以 OpenAI o1-preview 实际尺寸应该小于 GPT-4 及 GPT-4o,即使在这样的条件下 OpenAI 也大量限制了客户端的调用数量。可见该算法对于 RL 算法基础设施的要求很高,推理时的超长 kv-cache 管理能力要求也不低。
o1-preview 版本对应图中的非满血版,所以展望未来,大语言模型在各个领域通过稀疏的全局奖励信号加上 Self-Play 突破专有领域应该是一个比较确定的技术方向。OpenAI o1-preview 目前看起来虽像是一个领域模型, 不过随着领域的扩展我们应该能够很快看到满血的 o1,o2 等模型再振 RL 之雄光。
#07
First,whatisgoingonhere?
Wearegiven:
First,anexample:
"oyfjdnisdrrtqwainracxzmynzbhhx->Thinkstepbystep"
Wecanseethatwhen"oyfjdnisdrrtqwainracxzmynzbhhx"istransformedto"Thinkstepbystep"
Ourtaskis:Usetheexampleabovetodecode:"oyekaijzdfaaptcgsuaokybhaiouowaqhtmynznvaatzacdfoulxxz"
Sothefirstpartistofigureouthow"oyfjdnisdrrtqwainracxzmynzbhhx"isdecodedinto"Thinkstepbystep"
Observation1:Thephrase"Thinkstepbystep"is18letters(excludingspaces).Let'scounttheletters.
Similarly,let'scountthelettersin"oyfjdnisdrrtqwainracxzmynzbhhx"
OriginalCiphertext:
oyfjdnisdrrtqwainracxzmynzbhhx
Plaintext:
Thinkstepbystep
First,breakdowntheletters:
Ciphertextletters
yfjdnisdrrtqwainracxzmynzbhhx
Totalletters
et'scountthelettersintheciphertext.
Firstword
yfjdnisdr(10letters)
Secondword:rtqwainr(8letters)
Thirdword:acxz(4letters)
Fourthword:mynzbhhx(8letters)
Totallettersinciphertext:10+8+4+8=30letters
Plaintext:Thinkstepbystep
Firstword:Think(5letters)
Secondword:step(4letters)
Thirdword:by(2letters)
Fourthword:step(4letters)
Totallettersinplaintext:5+4+2+4=15letters
Hmm.
Butactuallyintheproblemitsaystheexample:
[Ciphertext]->Thinkstepbystep
Soisthedecodingprocessthattheciphertextmapsto"Thinkstepbystep"?
Ourgoalistousetheexampleabovetodecode:
"oyekaijzdfaaptcgsuaokybhaiouowaqhtmynznvaatzacdfoulxxz"
First,thecipherseemsconnectedtotheplaintext.
Giventhetimeconstraints,perhapstheeasiestwayistotrytoseepatterns.
Option1:Trytofindmappingfromletterstoletters.
Doanylettersmatch?
First,let'swritedowntheciphertextandplaintextlettersontopofeachother.
Ciphertext
yfjdnisdrrtqwainracxzmynzbhhx
Plaintext:Thinkstepbystep
Waitaminute.
Ithinkmaybethereisananagramorsubstitutioncipherhere.
Alternatively,Ithinkthatwecannoticethateachgroupofciphertextcorrespondstoaplaintextword.
Checkthenumberofletters.
Firstciphertextword
yfjdnisdr(10letters)
Firstplaintextword:Think(5letters)
Hmm.
Secondciphertextword:rtqwainr(8letters)
Secondplaintextword:step(4letters)
Thirdciphertextword:acxz(4letters)
Thirdplaintextword:by(2letters)
Fourthciphertextword:mynzbhhx(8letters)
Fourthplaintextword:step(4letters)
Interesting.
Itseemsthattheciphertextwordsareexactlytwiceaslongastheplaintextwords.
(10vs5,8vs4,4vs2,8vs4)
Idea:Maybeweneedtotakeeveryotherletterorrebuildtheplaintextfromtheciphertextaccordingly.
Let'stestthistheory.
Ifwetakeeveryotherletterfromtheciphertextwords,maybewe'llgettheplaintext.
Let'strythisforthefirstword:
Ciphertextword
yfjdnisdr(10letters)
Alternateletters:
Firstletters(positions1,3,5,7,9)
fdid
Secondletters(positions2,4,6,8,10):yjnsr
Wait
et'strytakingeverysecondletterorfirstletter.
Option1:Taketheoddpositions:
Positions:13579
Letters
fdid
Plaintextwordis"Think",lettersareThink
Hmm.
Perhapswecanmapletters:
ofdid-->Think
Notdirectly
Option2:Trymappingasperanassignedcode:perhapscolumnsofletters?
Alternatively,perhapsthecipherismorecomplex.
Alternatively,noticethat"oyfjdnisdr"has10lettersand"Think"has5letters.
Whatifeachplaintextletterisbeingrepresentedbytwociphertextletters?
Similarlyforotherwords.
Supposethateachplaintextlettercorrespondstopairoflettersintheciphertext.
Meaningthatthefirsttwolettersofciphertextmaptothefirstplaintextletter,andsoon.
Soforthefirstword,partitiontheciphertextlettersintopairs:
oyfjdnisdr
CorrespondingtoplaintextlettersThink
Sowecanattempttomap:
oy->T
fj->h
dn->i
is->n
dr->k
Ifthisisthemapping,perhapseachpairoflettersmapstooneplaintextletter.
Similarlyforotherwords.
Let'stestthismapping.
Isthereaconsistentmappingfrompairstoletters?
Let'smakeatableofpairsandcorrespondingletters.
First,makethepairsfromthefirstwordandtheircorrespondingplaintextletters:
CiphertextPairs->
laintextLetter
oy->T
fj->h
dn->i
is->n
dr->k
Now,what'sthemappingfrom"oy"to'T'?
Isthereawaytomap'oy'to'T'?
Similarlyforothers.
Onepossiblewayisthat'oy'represents'T'.
Buthow?
Option1:Sumoftheletters.
Convertletterstonumbers(A=1,B=2,...,Z=26)
Solet'strytogetto'T'from'o'and'y'
o=15
y=25
Sum:15+25=40
But'T'is20.
Alternatively,perhapssubtract:25-15=10.
No.
Alternatively,perhapscombinethenumbersinsomeway.
Alternatively,thinkabouttheirpositionsinthealphabet.
Alternatively,perhapsthelettersareencryptedviaacode.
Alternatively,perhapsifweoverlaytheword'Think'overthecipherpairs'oy','fj',etc.,thecipherisformedbysubstitutingeachplaintextletterwithtwoletters.
Alternatively,perhapsconsiderthe'original'letters.
Let'slookatthelettersbetweentheword"Think"and"oyfjdnisdr"
Perhapswecanspotthat"oyfjdnisdr"isananagramfor"Thinkfiles"?
Butthatseemsunlikely.
Alternatively,thinkofthepairs.
Supposeweassignnumberstoletters:a=1,b=2,...,z=26
Considerthenumbersin'oy':
o=15
y=25
Addthem:15+25=40
Now,for'T'wehave:
'T'isnumber20
Whatifwetakethesumofthecipherpairmod26.
15+25=40
Then40mod26=14
14correspondsto'N'
Doesn'tmatch.
Alternatively,seeifthecipherpairscorrespondtosomethingelse.
Alternatively,perhapsthepair'oy'correspondsto'T'viakey.
Alternatively,perhapsit'sassimpleas'oy'is'T'.
But'o'correspondsto'T',subtracting'o'ASCIIcodefrom'T'.
Now,let'sthinkintermsofsymmetricletters.
Alternatively,perhapswecanspotthattheletterscorrespondtothefirstlettersofwords.
Butperhapsaneasierwayistolookatthewordpositions.
Alternatively,perhapswecanseethattheciphertextlettersareoffsetsfromtheplaintextletters.
Solet'strytomapthepairstotheplaintextletters.
Firstpair'oy'andplaintextletter'T'
Letter'o'is15,'T'is20
Letter'o'+5='T'(15+5=20)
But'y'is25,whichis5lettersafter'T'(20+5=25)
Interesting,seemsthat'o'+5='T'
Similarly,'y'+1='Z',whichisnot'T'.
Alternatively,maybetheaverageofthetwoletterscorrespondsto'T'
(15+25)/2=20,whichis'T'
Waitaminute,thatseemspromising.
Firstpair:'o'(15)+'y'(25)=40
40/2=20
20correspondsto'T'
Soperhapstheaverageofthelettersinthepaircorrespondstotheplaintextletter.
Let'scheckthiswiththesecondpair.
Secondpair:'fj'correspondingto'h'
Letters'f'=6,'j'=10
Sum:6+10=16
Average:16/2=8
8correspondsto'h'(since'h'is8)
Success!
Thirdpair:'dn'to'i'
'd'=4,'n'=14
Sum:4+14=18
Average:18/2=9
9correspondsto'i'(9='i')
But'i'is9,sothatseemsoffby1.
Soperhapsweneedtothinkcarefullyaboutletters.
Wait,18/2=9,9correspondsto'I'
Sothisworks.
Fourthpair:'is'correspondingto'n'
'i'=9,'s'=19
Sum:9+19=28
Average:28/2=14
14correspondsto'n'(14='N')
Yes!
Fifthpair:'dr'correspondsto'k'
'd'=4,'r'=18
Sum:4+18=22
Average:22/2=11
11correspondsto'k'(11='K')
Perfect!
Soourcodeis:Foreachpair,sumtheirnumericvalues,divideby2,getthecorrespondingletter.
Alternatively,theaverageofthenumericvaluesoftheletterscorrespondstotheplaintextletter.
Thisseemstobeavalidmethod.
Nowlet'stestthiswiththeotherwords.
Secondwordciphertext:rtqwainr
Ciphertextpairs:
rt->s
qw->?
ai->?
nr->?
Correspondingtoplaintextletters's','t','e','p'
Solet'stakethepairs:
1.'rt'correspondsto's'
r=18,t=20
Sum:38
Average:19
19correspondsto's'(19='S')
Good
2.'qw'correspondsto't'
q=17,w=23
Sum:17+23=40
Average:20
20correspondsto't'(20='T')
Good
3.'ai'correspondsto'e'
a=1,i=9
Sum:10
Average:5
5correspondsto'e'(5='E')
Good
4.'nr'correspondsto'p'
n=14,r=18
Sum:32
Average:16
16correspondsto'p'(16='
')
Perfect!
Thirdword:acxz(4letters)
Plaintextword:'by'(2letters)
Ciphertextpairs:
ac
xz
Plaintextletters:'b','y'
Firstpair:'a','c'
a=1,c=3
Sum:4
Average:2
2correspondsto'b'(2='B')
Secondpair:'x'and'z'
x=24,z=26
Sum:50
Average:25
25correspondsto'y'(25='Y')
Yes!
Fourthword:mynzbhhx(8letters)
Plaintextword:'step'(4letters)
Ciphertextpairs:
my
nz
bh
hx
Plaintextletters's','t','e','p'
Firstpair'm','y'
m=13,y=25
Sum:38
Average:19
19correspondsto's'(19='S')
Secondpair:'n','z'
n=14,z=26
Sum:40
Average:20
20='t'
Thirdpair:'b','h'
b=2,h=8
Sum:10
Average:5
5='e'
Fourthpair:'h','x'
h=8,x=24
Sum:32
Average:16
16='p'
Gotit!
Now,giventhis,wecandecodethegivenmessage.
Ciphertexttodecode:
"oyekaijzdfaaptcgsuaokybhaiouowaqhtmynznvaatzacdfoulxxz"
First,weneedtodivideintowords.
Giventhattheciphertextintheexamplehadwordsoflength:
-10letters(5pairs)
-8letters(4pairs)
-4letters(2pairs)
-8letters(4pairs)
Transportedtoplaintextwordsof:
-5letters
-4letters
-2letters
-4letters
Soperhapsinoursuppliedciphertext,weneedtodividethelettersintowordsaccordingly.
Ciphertext
yekaijzdfaaptcgsuaokybhaiouowaqhtmynznvaatzacdfoulxxz
First,let'swritethelettersinorder:
1)oyekaijzdf(10letters)->wordof5letters
2)aaptcg(6letters)->wordof3letters
3)suaokybhai(10letters)->wordof5letters
4)ouow(4letters)->wordof2letters
5)aqht(4letters)->wordof2letters
6)mynznvaatzacdfoulxxz(22letters)->wordof11letters
Totals:
Sothelettersare:
Firstword
yekaijzdf(10letters=5pairs)
Secondword:aaptcg(6letters=3pairs)
Thirdword:suaokybhai(10letters=5pairs)
Fourthword
uow(4letters=2pairs)
Fifthword:aqht(4letters=2pairs)
Sixthword:mynznvaatzacdfoulxxz(22letters=11pairs)
Sowecansupposethattheplaintextwordshavelengths:
1)5letters
2)3letters
3)5letters
4)2letters
5)2letters
6)11letters
Nowwecanproceedtodecode.
Firstword:oyekaijzdf
Divideintopairs:
oy
ek
ai
jz
df
Sowecanfindtheplaintextlettersbyaveragingthenumericvaluesofthelettersineachpair.
Firstpair:'o','y'
o=15,y=25
Sum=40
Average=20
20='T'
Secondpair:'e','k'
e=5,k=11
Sum=16
Average=8
8='H'
Thirdpair:'a','i'
a=1,i=9
Sum=10
Average=5
5='E'
Fourthpair:'j','z'
j=10,z=26
Sum=36
Average=18
18='R'
Fifthpair:'d','f'
d=4,f=6
Sum=10
Average=5
5='E'
Sothefirstwordis'T','H','E','R','E'
So'THERE'
Secondword:aaptcg
Pairs:
aa
pt
cg
Firstpair:'a','a'
a=1,a=1
Sum=2
Average=1
1='A'
Secondpair:'p','t'
p=16,t=20
Sum=36
Average=18
18='R'
Thirdpair:'c','g'
c=3,g=7
Sum=10
Average=5
5='E'
Sosecondword:'A','R','E'
Thirdword:suaokybhai
Pairs:
su
ao
ky
bh
ai
Firstpair:s=19,u=21
Sum=40,Average=20
20='T'
Secondpair:a=1,o=15
Sum=16,Average=8
8='H'
Thirdpair:k=11,y=25
Sum=36,Average=18
18='R'
Fourthpair:b=2,h=8
Sum=10,Average=5
5='E'
Fifthpair:a=1,i=9
Sum=10,Average=5
5='E'
Thirdword:'T','H','R','E','E'
Fourthword:ouow
Pairs:ou,ow
Firstpair:o=15,u=21
Sum=36,Average=18
18='R'
Secondpair:o=15,w=23
Sum=38,Average=19
19='S'
Fourthword:'R','S'
Fifthword:aqht
Pairs:aq,ht
Firstpair:a=1,q=17
Sum=18,Average=9
9='I'
Secondpair:h=8,t=20
Sum=28,Average=14
14='N'
Fifthword:'I','N'
Sixthword:mynznvaatzacdfoulxxz(22letters:11pairs)
Pairs:
my
nz
nv
aa
tz
ac
df
ou
lx
xz
Let'slistthemproperly.
Wait,earlierImissedsomelettersthere.
Let'sre-expressthesixthwordletters:
mynznvaatzacdfoulxxz
Totalletters:22letters
Pairs:
1.my
2.nz
3.nv
4.aa
5.tz
6.ac
7.df
8.ou
9.lx
10.xx
11.z
Wait,that's21letters.
Butintotal,wehave22letters;IthinkIhaveamismatch.
Wait,intheproblemthesixthwordis:
mynznvaatzacdfoulxxz
Let'sseparatetheletters:
mynznvaatzacdfoulxxz
Totalletters:22letters
Sopairswouldbe:
1.my
2.nz
3.nv
4.aa
5.tz
6.ac
7.df
8.ou
9.lx
10.xx
11.z
Wait,'z'isonlyoneletterattheend.
Somaybethelettersare:
1.my
2.nz
3.nv
4.aa
5.tz
6.ac
7.df
8.ou
9.lx
10.xx
11.z(leftalone?)
Butthenwe'remissingaletter.
Alternatively,perhapsthe'z'attheendisanextraletterorit'spairedwiththeprevious'x'.
Alternatively,perhapsthereisamistake.
Alternatively,perhapswhenwereachthelast'xxz',weshouldwrite:
9.lx
10.xz
Totalpairs:11
Soupdatedpairs:
1.my
2.nz
3.nv
4.aa
5.tz
6.ac
7.df
8.ou
9.lx
10.xz
Nowtotalpairs:10pairs.Butwearesupposedtohave11lettersintheplaintextword.
SoperhapsIhavemiscountedandnotconsideredincluding'f'or'z'.
Wait,isthereanychancethatthesequenceis:
1.my
2.nz
3.nv
4.aa
5.tz
6.ac
7.df
8.ou
9.lx
10.xx
11.z
Wehave22letters.
Perhapsthe'xx'and'z'areoverlapping.
Butweneed11pairs.
Ithinkforthistowork,weneedtocreate11pairsfromthe22letters.
Solet'strypairinglettersinorder,takingtwolettersatatime.
1.my
2.nz
3.nv
4.aa
5.tz
6.ac
7.df
8.ou
9.lx
10.xx
11.z?
Butagain,lastpaironlyhasoneletter'z'
Alternatively,wemightneedtoadjustthepairs.
Perhapsit's'ou','lx','xz',andthereisnoextra'x'.
MaybeImiswrote.
Wait,let'swritethelettersastheycome:
mynznvaatzacdfoulxxz
Positions:
1m
2y
3n
4z
5n
6v
7a
8a
9t
10z
11a
12c
13d
14f
15o
16u
17l
18x
19x
20z
So20letters.
Nowthatmakessense.
Nowwecandivideintopairs:
Pairs:
1.my
2.nz
3.nv
4.aa
5.tz
6.ac
7.df
8.ou
9.lx
10.xz
Totalof10pairs,whichwillcorrespondto10letters.
Butearlierwethoughtthewordwas11letters.
But10lettersmaybeacceptable.
Maybeweshouldproceedwiththe10pairs.
Firstpair:my
m=13,y=25
Sum=38
Average=19
19='S'
Secondpair:nz
n=14,z=26
Sum=40
Average=20
20='T'
Thirdpair:nv
n=14,v=22
Sum=36
Average=18
18='R'
Fourthpair:aa
a=1,a=1
Sum=2
Average=1
1='A'
Fifthpair:tz
t=20,z=26
Sum=46
Average=23
23='W'
Sixthpair:ac
a=1,c=3
Sum=4
Average=2
2='B'
Seventhpair:df
d=4,f=6
Sum=10
Average=5
5='E'
Eighthpair:ou
o=15,u=21
Sum=36
Average=18
18='R'
Ninthpair:lx
l=12,x=24
Sum=36
Average=18
18='R'
Tenthpair:xz
x=24,z=26
Sum=50
Average=25
25='Y'
Sothetenthwordis'S','T','R','A','W','B','E','R','R','Y'
Waitthat's10letters
Sothesixthwordis'STRAWBERRY',whichmakessense.
Soputtingallthesetranslatedletterstogether:
Firstword:'THERE'
Secondword:'ARE'
Thirdword:'THREE'
Fourthword:'RS'(?Doesn'tmakesense)
Wait,thefourthword,thepairswere:
ouow
Pairs:
Firstpair:ou
o=15,u=21
Sum=36,Average=18
18='R'
Secondpair:ow
o=15,w=23
Sum=38,Average=19
19='S'
Soweget'R','S'
Similarly,fifthword'IN'
'R','S''I','N'
Sothemessagesofaris
'THEREARETHREERSIN'
Andthen'STRAWBERRY'
Wait,let'sputthewordstogether:
'THEREARETHREERsINSTRAWBERRY'
Ithink'RS'is'R's',meaning'Rs'
Sothemessageis:
'THEREARETHREER'SINSTRAWBERRY'
Whichistrue.
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |