开发者

Crack the caesar cipher using SML

开发者 https://www.devze.com 2023-01-16 22:32 出处:网络
I\'m supposed to crack the Caesar cipher. I have to declare a function crack : int * int -> int so that if (k, c) are of the type int, where k is the decrypted text and c the encrypted text, calli

I'm supposed to crack the Caesar cipher. I have to declare a function crack : int * int -> int so that if (k, c) are of the type int, where k is the decrypted text and c the encrypted text, calling crack(k, c) will return the key (mod 10) n, which is needed to get c to k. An example would be that calling crack(20458790, 64892134) would return 4.

If c isn't a correctly encoding of k, the function doesn't have to actually work.

I hope I'm being clear enough here. I understand the actual assignment here (I have k and c, I need n), 开发者_C百科but I don't know how to show it in my code.


You didn't specify what should happen when the second number isn't a caesar encoding of the first, so I'm going to assume it does not matter.

So in order to get, you just need to take any digit (most conveniently the last) from the first number and subtract that from the digit at the same position of the second number.

In other words, you can just do: (c mod 10 - k mod 10) mod 10

0

精彩评论

暂无评论...
验证码 换一张
取 消