储物柜与饼干:五元素序列


31

挑战

一个简单的“间谍与间谍”挑战。

编写具有以下规范的程序:

  1. 该程序可以用任何语言编写,但不得超过512个字符(如本网站的代码块所示)。
  2. 该程序必须接受5个带符号的32位整数作为输入。它可以采用接受5个参数的函数,接受单个5元素数组的函数或从任何标准输入中读取5个整数的完整程序的形式。
  3. 程序必须输出一个带符号的32位整数。
  4. 当且仅当五个输入(被解释为一个序列)与程序员选择的特定算术序列(称为“键”)匹配时,程序才必须返回1。对于所有其他输入,该函数必须返回0。

算术序列具有以下特性:该序列的每个连续元素都等于其前任元素加上某个固定常数a

例如,25 30 35 40 45是算术序列,因为序列中的每个元素都等于其前任加5。同样,17 10 3 -4 -11是算术序列,因为序列中的每个元素都等于其前任加-7。

序列1 2 4 8 163 9 15 6 12不是算术序列。

密钥可以是您选择的任何算术序列,唯一的限制是不允许涉及整数溢出的序列。也就是说,序列必须严格增加,严格减少或所有元素相等。

例如,假设您选择键98021 93880 89739 85598 81457。如果输入(按顺序)与这五个数字匹配,则程序必须返回1,否则返回0。

请注意,保护钥匙的方法应该是您自己新颖的设计。同样,不允许以任何非零概率返回假阳性的概率解。特别是,请勿使用任何标准密码哈希,包括用于标准密码哈希的库函数。

计分

每个字符计数中最短的未破解提交将被宣布为获胜者。

如果有任何混淆,请随时提出或评论。

反挑战

鼓励所有读者,包括提交了自己程序的读者,“破解”提交的内容。当提交的密钥发布在关联的注释部分时,该提交将被破解。如果提交的内容持续存在72小时而不被修改或破解,则被认为是“安全的”,随后在破解方面的任何成功都将被视为比赛的原因。

有关更新的破解分数政策的详细信息,请参见下面的“免责声明”。

破解的提交将被排除在争用之外(前提是它们“不安全”)。不应对其进行编辑。如果读者希望提交新程序,则应在单独的答案中提交。

得分最高的饼干将与获奖程序的开发者一起宣布为获奖者。

请不要破解您自己的提交。

祝你好运。:)

排行榜

倒数第二的排名(在丹尼斯提交的CJam 49提交文件中处于安全状态)。

安全储物柜

  1. 丹尼斯CJam 49
  2. CJam 62,丹尼斯 保险柜
  3. CJam 91,丹尼斯 保险柜
  4. Python 156,Maarten Baert 安全
  5. Perl 256, 安全的
  6. Java 468,Geobits 安全

不可阻挡的饼干

  1. 彼得·泰勒 [Ruby 130,Java 342,Mathematica 146 *,Mathematica 72 *,CJam 37]
  2. 丹尼斯[Pyth 13,Python 86 *,Lua 105 *,GolfScript 116,C 239 *]
  3. MartinBüttner[Javascript 125,Python 128 *,Ruby 175 *,Ruby 249 *]
  4. Tyilo [C 459,Javascript 958 *]
  5. freddieknets [Mathematica 67 *]
  6. Ilmari Karonen [Python27 182 *]
  7. 亚硝酸盐[C 212 *]

*不符合规定的提交

免责声明(8月26日,美国东部标准时间11:15更新)

随着计分问题最终达到临界质量(到目前为止,三分之二的不合格提交都是不合规的),我已经按照破解的提交数量(主要)和合规的不合格提交中的字符总数来排名最高的饼干(第二)。

像以前一样,已破解的确切提交内容,提交的时间长度以及它们的合规/不合规状态均已标记,以便读者如果认为新的官方排名不公平,则可以推断自己的排名。

我很抱歉在比赛后期修改规则。


6
您将如何验证程序是否符合第4点?您是否希望人们编辑他们的安全答案以添加证明?在假设哈希函数是理想的并且与48位空间(根据您上面的估计)中的另一个元素发生碰撞的可能性很小的基础上,是否允许概率提交?
彼得·泰勒

2
计分系统似乎鼓励了破解者忽略最短的锁,因为他们通过破解两个长锁比两个小锁得分更高。
彼得·泰勒

3
@COTO我认为问题在于,您只能获得2个破解分数,而且得分最短。那么,为什么不等待和希望,并且希望会更长呢?例如,马丁现在没有动力破解我的(更长的)锁,因为他已经破解了两个较短的锁。现在,任何破解我的人都将击败他,而无需再进行第二次。
Geobits,2014年

1
我认为更好的评分系统可能是问题和破解之间的总时间总和。这样一来,破解一堆简单的漏洞就可以被击败,而真正的回报则来自破解那些真正困难的漏洞。
isaacg 2014年

1
我是打高尔夫球的新手,所以也许这是一个愚蠢的问题,对此感到抱歉。为什么用字符而不是字节来测量代码长度?后者实际上是程序占用的内存空间,因此对我来说似乎更合逻辑。例如。CJam的答案是字符中最短的字符,但是当看它的大小(由于unicode时为326)时,它甚至不在前5位。所以我想知道,打高尔夫球而不是字节计数是惯例吗?
freddieknets 2014年

Answers:


3

CJam,62个字符

"ḡꬼ쏉壥떨ሤ뭦㪐ꍡ㡩折量ⶌ팭뭲䯬ꀫ郯⛅彨ꄇ벍起ឣ莨ຉᆞ涁呢鲒찜⋙韪鰴ꟓ䘦쥆疭ⶊ凃揭"2G#b129b:c~

Stack Exchange易于损坏不可打印的字符,但会从以下位置复制代码 粘贴中并将其粘贴到CJam解释器中对我来说很好。

怎么运行的

用ASCII字符串替换Unicode字符串后,将执行以下代码:

" Push 85, read the integers from STDIN and collect everything in an array.               ";

85l~]

" Convert the array of base 4**17 digits into and array of base 2 digits.                 ";

4H#b2b

" Split into chunks of length 93 and 84.                                                  ";

93/~

" Do the following 611 times:

    * Rotate array A (93 elements) and B one element to the left.
    * B[83] ^= B[14]
    * T = B[83]
    * B[83] ^= B[0] & B[1] ^ A[23]
    * A[92] ^= A[26]
    * Rotate T ^ A[92] below the arrays.
    * A[92] ^= A[0] & A[1] ^ B[5].                                                        ";

{(X$E=^:T1$2<:&^2$24=^+\(1$26=^_T^@@1$2<:&^3$5=^+@}611*

" Discard the arrays and collects the last 177 generated bits into an array.              ";

;;]434>

" Convert the into an integer and check if the result is 922 ... 593.                     ";

2b9229084211442676863661078230267436345695618217593=

这种方法使用Bivium-B(请参阅类似Trivium的密码的代数分析),它是流密码Trivium的弱化版本。

该程序使用整数序列作为初始状态,更新状态434次(354轮达到完全扩散)并生成177位输出,并将其与正确序列的输出进行比较。

由于该州的大小恰好是177位,因此 应该足以唯一标识初始状态。

运行示例

$ echo $LANG
en_US.UTF-8
$ base64 -d > block.cjam <<< IgThuKHqrLzsj4nlo6XrlqjhiKTrrabjqpDqjaHjoanmipjvpb7itozuoIDtjK3rrbLul7bkr6zqgKvvjafpg6/im4XlvajqhIfrso3uprrotbfvmL/hnqPojqjguonhhp7mtoHujLPuipzlkaLpspLssJzii5npn6rpsLTqn5PkmKbspYbnlq3itorlh4Pmj60iMkcjYjEyOWI6Y34=
$ wc -m block.cjam
62 block.cjam
$ cjam block.cjam < block.secret; echo
1
$ cjam block.cjam <<< "1 2 3 4 5"; echo
0

6

CJam,91个字符

q~]KK#bD#"᫖࿼듋ޔ唱୦廽⻎킋뎢凌Ḏ끮冕옷뿹毳슟夫΢眘藸躦䪕齃噳卤"65533:Bb%"萗縤ᤞ雑燠Ꮖ㈢ꭙ㈶タ敫䙿娲훔쓭벓脿翠❶셭剮쬭玓ୂ쁬䈆﹌⫌稟"Bb=

Stack Exchange容易损坏无法打印的字符,但是会从此粘贴中复制代码并将其粘贴到CJam解释器中对我来说很好。

怎么运行的

用整数替换Unicode字符串后(通过考虑65535基数的字符数字),将执行以下代码:

" Read the integers from STDIN and collect them in an array.                               ";

q~]

" Convert it into an integer by considering its elements digits of a base 20**20 number.   ";

KK#b

" Elevate it to the 13th power modulus 252 ... 701.                                        ";

D#
25211471039348320335042771975511542429923787152099395215402073753353303876955720415705947365696970054141596580623913538507854517012317194585728620266050701%

" Check if the result is 202 ... 866.                                                      ";

20296578126505831855363602947513398780162083699878357763732452715119575942704948999334568239084302792717120612636331880722869443591786121631020625810496866=

由于13是模数的总和(该总代理是秘密的,因此您只需要信任我),因此不同的基数将产生不同的结果,即,解决方案是唯一的。

除非有人可以利用小指数(13),否则打破此锁的最有效方法是分解模数(请参阅RSA问题)。我为模数选择了512位整数,该整数应该可以承受72个小时的分解尝试。

运行示例

$ echo $LANG
en_US.UTF-8
$ base64 -d > lock.cjam <<< cX5dS0sjYkQjIgHuiJHhq5bgv7zrk4velOWUse6zjuCtpuW7veK7ju2Ci+uOouWHjOG4ju+Rh+uBruWGleyYt+u/ueavs+6boOyKn+Wkq86i55yY6Je46Lqm5KqV6b2D5Zmz75Wp5Y2kIjY1NTMzOkJiJSIB6JCX57ik4aSe74aS6ZuR54eg4Y+G44ii6q2Z44i244K/5pWr5Jm/5aiy7ZuU7JOt67KT7rO26IS/57+g4p2275+K7IWt5Ymu7Kyt546T4K2C7IGs5IiG77mM4quM56ifIkJiPQ==
$ wc -m lock.cjam
91 lock.cjam
$ cjam lock.cjam < lock.secret; echo
1
$ cjam lock.cjam <<< "1 2 3 4 5"; echo
0

由于我忘记从第一个字符中删除不必要的字符,因此我发布了一个新版本。机密顺序仍然相同,因此您可以尝试破解其中一个。
丹尼斯

仅供参考,我正在中止我的保理尝试。msieve为自己设置了276小时的时间限制,但这只是为了建立要素基础。在那个时候found 1740001 rational and 1739328 algebraic entries; 从那时起,已经有将近100个小时来处理它们并进行报告sieving in progress b = 46583, 0 complete / 0 batched relations (need 44970493)
彼得·泰勒

@PeterTaylor:看起来512位是过大的。您是要在我的其他答案中还是在这个答案中考虑整数?
丹尼斯2014年

哦,糟糕 是的,另一个。
彼得·泰勒

4

的Python-128

让我们尝试一下:

i=input()
k=1050809377681880902769L
print'01'[all((i>1,i[0]<i[4],k%i[0]<1,k%i[4]<1,i[4]-i[3]==i[3]-i[2]==i[2]-i[1]==i[1]-i[0]))]

(希望用户输入5个逗号分隔的数字,例如1,2,3,4,5。)


3
32416190039,32416190047,32416190055,32416190063,32416190071
Martin Ender 2014年

哇,那太快了!你是对的!我出去了
法尔科2014年

3
顺便说一句,这实际上是无效的,因为您的五个整数不适合32位整数。
Martin Ender 2014年

4

爪哇:468

输入为k(int[5])。如果间隔不均,请提早保释。否则,需要花一点时间来确定所有十个散列是否正确。对于较大的数字,“一点”可能意味着十秒钟或更长时间,因此可能阻止饼干。

//golfed
int k(int[]q){int b=q[1]-q[0],i,x,y,j,h[]=new int[]{280256579,123883276,1771253254,1977914749,449635393,998860524,888446062,1833324980,1391496617,2075731831};for(i=0;i<4;)if(q[i+1]-q[i++]!=b||b<1)return 0;for(i=1;i<6;b=m(b,b/(i++*100),(1<<31)-1));for(i=0;i<5;i++){for(j=1,x=b,y=b/2;j<6;x=m(x,q[i]%100000000,(1<<31)-1),y=m(y,q[i]/(j++*1000),(1<<31)-1));if(x!=h[i*2]||y!=h[i*2+1])return 0;}return 1;}int m(int a,int b,int c){long d=1;for(;b-->0;d=(d*a)%c);return (int)d;}

// line breaks
int k(int[]q){
    int b=q[1]-q[0],i,x,y,j,
    h[]=new int[]{280256579,123883276,1771253254,1977914749,449635393,
                  998860524,888446062,1833324980,1391496617,2075731831};
    for(i=0;i<4;)
        if(q[i+1]-q[i++]!=b||b<1)
            return 0;
    for(i=1;i<6;b=m(b,b/(i++*100),(1<<31)-1));
    for(i=0;i<5;i++){
        for(j=1,x=b,y=b/2;j<6;x=m(x,q[i]%100000000,(1<<31)-1),y=m(y,q[i]/(j++*1000),(1<<31)-1));
        if(x!=h[i*2]||y!=h[i*2+1])
            return 0;
    }
    return 1;
}
int m(int a,int b,int c){
    long d=1;for(;b-->0;d=(d*a)%c);
    return (int)d;
}

1
如果输入算术序列降序,则代码将挂起。或者至少需要长时间。这让我觉得密码在上升……
Keith Randall 2014年

3
@KeithRandall糟糕。让我们添加四个字节以使降序序列花费的时间异常,从而进一步增强了您的信念。
Geobits 2014年

4

爪哇:342

int l(int[]a){String s=""+(a[1]-a[0]);for(int b:a)s+=b;char[]c=new char[11];for(char x:s.toCharArray())c[x<48?10:x-48]++;for(int i=0;i<11;c[i]+=48,c[i]=c[i]>57?57:c[i],i++,s="");for(int b:a)s+=new Long(new String(c))/(double)b;return s.equals("-3083.7767567702776-8563.34366442527211022.4345579010483353.1736981951231977.3560837512646")?1:0;}

这是一个基于字符串的储物柜,它取决于输入字符数和特定的输入。该顺序可能基于模糊的流行文化参考。玩得开心!

有点不满意:

int lock(int[]a){
    String s=""+(a[1]-a[0]);
    for(int b:a)
        s+=b;
    char[]c=new char[11];
    for(char x:s.toCharArray())
        c[x<48?10:x-48]++;
    for(int i=0;i<11;c[i]+=48,
                     c[i]=c[i]>57?57:c[i],
                     i++,
                     s="");
    for(int b:a)
        s+=new Long(new String(c))/(double)b;
    return s.equals("-3083.7767567702776-8563.34366442527211022.4345579010483353.1736981951231977.3560837512646")?1:0;
}

2
8675309?90210?
玛拉基2014年

1
@Malachi毫无疑问,有两个出色的参考文献,但我既不能确认也不能否认它们在本练习中的适用性。
Geobits 2014年

大声笑,我还没有完全弄清楚这个挑战是如何完成的,我以后在家时可以试一试。
玛拉基2014年

1
初始项是-8675309,增量是5551212
彼得·泰勒

@PeterTaylor做得好:)
Geobits

4

Python,147

编辑:基于丹尼斯评论的较短版本。我也更新了序列,以避免泄漏任何信息。

def a(b):
    c=1
    for d in b:
        c=(c<<32)+d
    return pow(7,c,0xf494eca63dcab7b47ac21158799ffcabca8f2c6b3)==0xa3742a4abcb812e0c3664551dd3d6d2207aecb9be

基于被认为无法破解的离散对数问题,但是我使用的素数可能太小而无法保证安全(并且我可能不知道它可能还有其他问题)。当然,您可以对其进行暴力破解,因为唯一的未知数是两个32位整数。


我认为离散对数要难得多。我的饼干在这里已经26个小时了。我放弃。
丹尼斯

您可以通过初始化c=1,计算c=(c<<32)+d并相应地更改常数来解决符号问题。
丹尼斯

3

JavaScript 125

这应该很快被破解。我会跟进一些更强的东西。

function unlock(a, b, c, d, e)
{
    return (e << a == 15652) && (c >> a == 7826) && (e - b == d) && (d - c - a == b) ? 1 : 0;
}

6
0, 3913, 7826, 11739, 15652
Martin Ender 2014年

是的,你知道了:)
rdans

3

红宝石175

a=gets.scan(/\d+/).map(&:to_i)
a.each_cons(2).map{|x,y|x-y}.uniq[1]&&p(0)&&exit
p a[2]*(a[1]^a[2]+3)**7==0x213a81f4518a907c85e9f1b39258723bc70f07388eec6f3274293fa03e4091e1?1:0

与使用密码哈希或不同srand,它是唯一可证明的(这是一个线索)。通过STDIN接受五个数字,以任何非数字,非换行符或多个字符分隔。输出到STDOUT。


是的,忘记了他们的签名。
histocrat

2
622238809,1397646693,2173054577,2948462461,3723870345(我以前的猜测有一个错误,但是这个已经过测试)。我认为这不是有效的,因为最后一个数字不适合有符号的32位整数。
Martin Ender 2014年

3

GolfScript(116个字符)

将输入作为空格分隔的整数。

~]{2.5??:^(&}%^base 2733?5121107535380437850547394675965451197140470531483%5207278525522834743713290685466222557399=

2
-51469355 -37912886 -24356417 -10799948 2756521
丹尼斯

辛苦了 您是否利用了小指数?
彼得·泰勒

2
不,我将模数分解了。使用primo的多项多项式二次筛和PyPy 仅花费了13秒。
丹尼斯2014年

在那种情况下,我不妨通过使用紧凑表示的模量放弃当前的高尔夫运动。如果结果必须为1024位左右才能安全分解,那么即使使用base-256表示形式,也将太长。
彼得·泰勒

我希望不是。我的答案与您的想法相同,但是具有512位模数和更小的指数(13)。考虑到72小时的时间限制,这可能就足够了
丹尼斯

3

C 459字节

提洛(Tilolo)解决了-阅读下面的内容

int c (int* a){
int d[4] = {a[1] - a[0], a[2] - a[1], a[3] - a[2], a[4] - a[3]};
if (d[0] != d[1] || d[0] != d[2] || d[0] != d[3]) return 0;
int b[5] = {a[0], a[1], a[2], a[3], a[4]};
int i, j, k;
for (i = 0; i < 5; i++) { 
for (j = 0, k = 2 * i; j < 5; j++, k++) {
k %= i + 1;
b[j] += a[k];
}
}
if (b[0] == 0xC0942 - b[1] && 
b[1] == 0x9785A - b[2] && 
b[2] == 0x6E772 - b[3] && 
b[3] == 0xC0942 - b[4] && 
b[4] == 0xB6508 - b[0]) return 1;
else return 0;
}

我们需要有人来编写C解决方案,不是吗?我并没有给任何人留下深刻的印象,我不是高尔夫球手。我希望这是一个有趣的挑战!

我认为没有明显的破解方法,我热切等待所有尝试!我知道这种解决方案是独一无二的。非常小的混淆,主要满足长度要求。可以简单地测试一下:

int main(){
    a[5] = {0, 0, 0, 0, 0} /* your guess */
    printf("%d\n", c(a));
    return 0;
}

附言: a[0]:数字本身,我想看看有人在评论中指出这一点!

编辑:

解: 6174, 48216, 90258, 132300, 174342

关于破解的注意事项:

虽然这不是使用的方法(请参阅评论),但我确实碰巧用非常容易的暴力破解了自己的密码。我现在了解,使数字更大至关重要。以下代码可以破解任何密码upper_bound已知上限的a[0] + a[1] + a[2] + a[3] + a[4]。上面密码的上限是457464,可以从该算法的方程组b[]和该算法的某些基础上得出。可以证明b[4] = a[0] + a[1] + a[2] + a[3] + a[4]

int a[5];
for (a[0] = 0; a[0] <= upper_bound / 5; a[0]++) {
    for (a[1] = a[0] + 1; 10 * (a[1] - a[0]) + a[0] <= upper_bound; a[1]++) {
        a[2] = a[1] + (a[1] - a[0]);
        a[3] = a[2] + (a[1] - a[0]);
        a[4] = a[3] + (a[1] - a[0]);
        if (c(a)) {
            printf("PASSED FOR {%d, %d, %d, %d, %d}\n", a[0], a[1], a[2], a[3], a[4]);
        }
    }
    printf("a[0] = %d Checked\n", a[0]);
}

使用a[0] = 6174,此循环在不到一分钟的时间内中断了我的工作。


6
解决方案:6174, 48216, 90258, 132300, 174342
Tyilo 2014年

哇,太快了。好东西。暴力破解,还是您找到了我错过的聪明东西?
BrainSteel 2014年

我使用了Mathematica的符号评估,如下所示:ghostbin.com/paste/jkjpf屏幕截图:i.imgur.com/2JRo7LE.png
Tyilo

重新编辑:我基本上做了同样的事情,但是将鞋帮的价格定为500k。得到了答案,看到Tyilo已经发布了:(
Geobits

@Geobits这是一个令人惊讶的准确猜测。应该在这些数字的末尾再加上0。
BrainSteel 2014年

3

Mathematica 80 67

f=Boole[(p=NextPrime/@#)-#=={18,31,6,9,2}&&BitXor@@#~Join~p==1000]&

正在运行:

f[{1,2,3,4,5}] (* => 0 *)

可能很容易破解,也可能有多种解决方案。

更新:通过执行马丁·布特纳(MartinBüttner)的建议来改善高尔夫运动。功能和键的功能未更改。


@MartinBüttner改善答案,以便在破解时获得更高的分数。Smart; P
Tyilo

呵呵,结果我跳过了有关反击得分的段落。我以为那只是为了好玩,一点都没有。虽然我认为缩短我想破解的解决方案对我来说没有意义,因为这会降低我的分数。
马丁·恩德

4
{58871,5592,-47687,-100966,-154245}
freddieknets

@freddieknets不是我在创建它时使用的解决方案。不知道那NextPrime会返回负值。你是怎样找到它的?
Tyilo 2014年

那么您的密钥不是唯一的:p。我只是进行了一些测试-NextPrime [#]-#的求和结果确实不多,所以这是破解它的一种简便方法。
freddieknets

2

Python27,283 182

好的,我对我的储物柜非常有信心,但是只要我在输入中添加了“难于反转”的计算,就可以使它很好-很难反转。

import sys
p=1
for m in map(int,sys.argv[1:6]):m*=3**len(str(m));p*=m<<sum([int(str(m).zfill(9)[-i])for i in[1,3,5,7]])
print'01'[p==0x4cc695e00484947a2cb7133049bfb18c21*3**45<<101]

编辑:感谢colevk的进一步打高尔夫球。我意识到在编辑过程中我的算法既有缺陷也有缺陷,也许下次我会比较幸运。


5
在参数重新排序下这是不变的,因此它不是有效的储物柜。
彼得·泰勒

此外,我怀疑发布的代码有问题:该键121174841 121174871 121174901 121174931 121174961有效,但仅当第[1,3,5,7]7行的列表替换为时[1,3,5,7,11]
Ilmari Karonen 2014年

达恩,是的,我只是在修正拼写错误,在此期间我在算法中犯了一个关键错误,很容易破解:|
stokastic,2014年

实际上,发现并修复该错误是困难的部分。给定您的算法,考虑常数是一种显而易见的尝试。
Ilmari Karonen

2

数学142 146

编辑:键不是唯一的,添加了4个字符,现在是。

n=NextPrime;
f=Boole[
    FromDigits /@ (
        PartitionsQ[n@(237/Plus@##) {1, ##} + 1] & @@@ 
            IntegerDigits@n@{Plus@##-37*Log[#3],(#1-#5)#4}
    ) == {1913001154,729783244}
]&

(为了便于阅读,添加了空格和换行符,不计算在内,不需要)。

用法:

f[1,2,3,4,5]   (* => 0 *)

1
初始项256208,增量-5
彼得·泰勒

Dang,那仍然不是唯一的,因为这不是我的原始钥匙。你有暴力吗?
freddieknets 2014年

测试它,我可能犯了一个错误,因为我没有访问Mathematica进行测试的权限。每个阶段都在使用蛮力,但是并不需要多少计算机时间。方法是向后工作到的输出,IntegerDigits然后分解以获取初始项和增量的候选值。
彼得·泰勒

但是无论如何,这种方法不可能是独一无二的。五个输入中的第二个仅用于传递给的总和中NextPrime;如果我们将其乘以正负1,则其中至少一个会给出相同的下一个质数。
彼得·泰勒

是的,但是对于算术序列-所需的输入-应该是唯一的。
freddieknets 2014年

1

在2小时内被@Dennis破解


只是一个开始的简单方法-我完全希望这会很快得到破解。

珀斯 13

h_^ZqU5m-CGdQ

在STDIN上使用逗号分隔的输入。

像这样运行它(-c表示将程序作为命令行参数):

$ echo '1,2,3,4,5' | python3 pyth.py -c h_^ZqU5m-CGdQ
0

修复了程序-我不了解规格。

这种语言可能对这场比赛来说太深奥了-如果OP认为如此,我将删除它。


7
您刚刚放弃了那1,2,3,4,5是关键吗?
彼得·泰勒

1
我尝试的每个输入都返回1,您是否将1和0切换为输出?
蒂洛2014年

抱歉,我不了解Output与Return的区别-该程序现在应该可以运行了。相同的基础算法。
isaacg 2014年

3
97,96,95,94,93 (I just killed my cracking score.)
Dennis

@Dennis Well done. The cracking score system needs to be changed - it's creating some really weird incentives.
isaacg

1

Lua 105

I suspect it won't be long before it's cracked, but here we go:

function f(a,b,c,d,e)
   t1=a%b-(e-2*(d-b))
   t2=(a+b+c+d+e)%e
   t3=(d+e)/2
   print(t1==0 and t2==t3 and"1"or"0")
end

(spaces added for clarity, but are not part of count)


3, 7, 11, 15, 19 or 6, 14, 22, 30, 38
Dennis

@Dennis: sadly it is neither of those. I'll have to work on it a bit later to ensure the non-uniqueness.
Kyle Kanos

t1==0 whenver S is increasing. Also, both conditions are homogeneous; if S is a solution, so is kS.
Dennis

1

Perl - 256

sub t{($z,$j,$x,$g,$h)=@_;$t="3"x$z;@n=(7,0,split(//,$g),split(//,$h),4);@r=((2)x6,1,1,(2)x9,4,2,2,2);$u=($j+1)/2;for$n(0..$#r+1){eval{substr($t,$j,1)=$n[$n]};if($@){print 0; return}$j+=$r[$n]*$u}for(1..$x){$t=pack'H*',$t;}eval$t;if($@||$t!~/\D/){print 0}}

I had to put in a lot of error handling logic and this can definitely be golfed down a lot more. It will print a 1 when you get the right five numbers. It will hopefully print a 0 for everything else (might be errors or nothing, I don't know). If anyone wants to help improve the code or golf it more, feel free to help out!


Call with:

t(1,2,3,4,5);

1

Ruby - 130

Based on Linear Feedback Shift Register. Inputs by command line arguments.
Should be unique based on the nature of LFSRs. Clue: ascending and all positive.

Will give more clues if no one solves it soon.

x=($*.map{|i|i.to_i+2**35}*'').to_i
(9**8).times{x=((x/4&1^x&1)<<182)+x/2}
p x.to_s(36)=="qnsjzo1qn9o83oaw0a4av9xgnutn28x17dx"?1:0

3
Initial value 781783, increment 17982811
Peter Taylor

@PeterTaylor Argh... =)
Vectorized

1

Ruby, 249

a=gets.scan(/\d+/).map(&:to_i)
a.each_cons(2).map{|x,y|x-y}.uniq[1]&&p(0)&&exit
r=(a[0]*a[1]).to_s(5).tr'234','(+)'
v=a[0]<a[1]&&!r[20]&&(0..3).select{|i|/^#{r}$/=~'%b'%[0xaa74f54ea7aa753a9d534ea7,'101'*32,'010'*32,'100'*32][i]}==[0]?1:0rescue 0
p v

Should be fun. Who needs math?


2
309, 77347, 154385, 231423, 308461 but I don't think it's unique.
Martin Ender

Yeah, it's not. For the same regex (i.e. product of the first two numbers), I also find 103, 232041, 463979, 695917, 927855 and 3, 7966741, 15933479, 23900217, 31866955. And I'm pretty sure there are other valid regexes by using additional +s.
Martin Ender

Sorry, I guess I messed up the test string. There was supposed to be only one regexp with a unique factorization.
histocrat

If you want to try to fix it, make sure to take possessive quantifiers into account. I can also create a larger, equivalent regex by inserting () or similar.
Martin Ender

1

CJam, 49 characters

"腕옡裃䃬꯳널֚樂律ࡆᓅ㥄뇮┎䔤嬣ꑙ䘿휺ᥰ籃僾쎧諯떆Ἣ餾腎틯"2G#b[1q~]8H#b%!

Try it online.

How it works

" Push a string representing a base 65536 number and convert it to an integer.            ";

"腕옡裃䃬꯳널֚樂律ࡆᓅ㥄뇮┎䔤嬣ꑙ䘿휺ᥰ籃僾쎧諯떆Ἣ餾腎틯"2G#b

" Prepend 1 to the integers read from STDIN and collect them into an array.               ";

[1q~]

" Convert that array into an integer by considering it a base 2**51 number.               ";

8H#b

" Push the logical NOT of the modulus of both computed integers.                          ";

%!

The result will be 1 if and only if the second integer is a factor of the first, which is a product of two primes: the one corresponding to the secret sequence and another that doesn't correspond to any valid sequence. Therefore, the solution is unique.

Factorizing a 512 bit integer isn't that difficult, but I hope nobody will be able to in 72 hours. My previous version using a 320 bit integer has been broken.

Example run

$ echo $LANG
en_US.UTF-8
$ base64 -d > flock512.cjam <<< IuiFleyYoeijg+SDrOqvs+uEkNaa76a/5b6L4KGG4ZOF76Gi46WE64eu4pSO5JSk5ayj6pGZ5Ji/7Zy64aWw57GD5YO+7I6n6Kuv65aG7qK04byr6aS+6IWO7rSn7YuvIjJHI2JbMXF+XThII2IlIQ==
$ wc -m flock512.cjam
49 flock512.cjam
$ cjam flock512.cjam < flock512.secret; echo
1
$ cjam flock512.cjam <<< "1 2 3 4 5"; echo
0

I've had msieve running on it for over 24 hours, but since its self-imposed time limit is 276.51 CPU-hours and I've only given it one CPU I'm not optimistic.
Peter Taylor

0

Javascript 958

Converts the inputs to a number of data types and performs some manipulations relevant to each data type along the way. Should be fairly easily reversed for anyone that takes the time.

function encrypt(num)
{
    var dateval = new Date(num ^ (1024-1) << 10);

    dateval.setDate(dateval.getDate() + 365);

    var dateString = (dateval.toUTCString() + dateval.getUTCMilliseconds()).split('').reverse().join('');

    var result = "";

    for(var i = 0; i < dateString.length; i++)
        result += dateString.charCodeAt(i);

    return result;
}

function unlock(int1, int2, int3, int4, int5)
{
    return encrypt(int1) == "5549508477713255485850495848483249555749321109774324948324410511470" && encrypt(int2) == "5756568477713252485848495848483249555749321109774324948324410511470" && encrypt(int3) == "5149538477713248485856485848483249555749321109774324948324410511470" && encrypt(int4) == "5356498477713256535853485848483249555749321109774324948324410511470" && encrypt(int5) == "5748568477713251535851485848483249555749321109774324948324410511470" ? 1 : 0;
}

5
Brute forced: 320689, 444121, 567553, 690985, 814417
Tyilo

@Tyilo If you stop now, I think no cracker can beat your score. ;)
Martin Ender

2
@MartinBüttner Unless this can be golfed to under 512 per the OP, I don't think it counts.
Geobits

0

C, 239 (Cracked by Dennis)

Go here for my updated submission.

Could probably be golfed a little more thoroughly. Admittedly, I haven't taken the time to prove the key is unique (it probably isn't) but its definitely on the order of a hash collision. If you crack it, please share your method :)

p(long long int x){long long int i;x=abs(x);
for (i=2;i<x;i++) {if ((x/i)*i==x) return 0;}return 1;}
f(a,b,c,d,e){char k[99];long long int m;sprintf(k,"%d%d%d%d%d",e,d,c,b,a);
sscanf(k,"%lld",&m);return p(a)&&p(b)&&p(c)&&p(d)&&p(e)&&p(m);}

1
So, 0 0 0 0 0?
Dennis

Sigh that was a bug, but yes that works.
Orby

I've updated with a corrected version that should be a little more interesting ;)
Orby

See the corrected version here.
Orby

0

C, 212 by Orby -- Cracked

https://codegolf.stackexchange.com/a/36810/31064 by Orby has at least two keys:

13 103 193 283 373
113 173 233 293 353

Orby asked for the method I used to crack it. Function p checks whether x is prime by checking x%i==0 for all i between 2 and x (though using (x/i)*i==x instead of x%i==0), and returns true if x is a prime number. Function f checks that all of a, b, c, d and e are prime. It also checks whether the number m, a concatenation of the decimal representations of e, d, c, b and a (in that order), is prime. The key is such that a,b,c,d,e and m are all prime.

Green and Tao (2004) show that there exist infinitely many arithmetic sequences of primes for any length k, so we just need to look for these sequences that also satisfy m being prime. By taking long long as being bounded by -9.223372037e+18 and 9.223372037e+18, we know that for the concatenated string to fit into long long, the numbers have an upper bound of 9999. So by using a python script to generate all arithmetic sequences within all primes < 10000 and then checking whether their reverse concatenation is a prime, we can find many possible solutions.

For some reason I came up with false positives, but the two above are valid according to the program. In addition there may be solutions where e is negative and the rest are positive (p uses the modulus of x), but I didn't look for those.

The keys I gave are all arithmetic sequences but Orby's script doesn't appear to actually require the inputs to be an arithmetic sequence, so there may be invalid keys too.


0

MATLAB: Apparently invalid

Very simple, you just have to generate the right random number.

function ans=t(a,b,c,d,e)
rng(a)
r=@(x)rng(rand*x)
r(b)
r(c)
r(d)
r(e)
rand==0.435996843156676

It can still error out, but that shouldn't be a problem.


1
This approach is prohibited in the comments. If it's not mentioned in the question, propose an edit. Sorry.
Peter Taylor

@PeterTaylor I guess I am out then, I will just leave it here without score as I am curious whether someone can find a weakness.
Dennis Jaheruddin

0

MATLAB (with Symbolic Toolbox), 173 characters

This isn't an official entry and won't count towards anyone's cracking score, but it will net you mad bragging rights. ;)

function b=L(S),c=sprintf('%d8%d',S(1),S(2)-S(1));b=numel(unique(diff(S)))==1&&numel(c)==18&&all(c([8,9])==c([18,17]))&&isequal(c,char(sym(sort(c,'descend'))-sym(sort(c))));

The symbolic toolbox is only required to handle subtraction of big integers.

Brute forcing it should be a dog, but if you're familiar with the series it involves, the solution is trivial.


0

Python 2 (91)

Edit: This isn't allowed because the argument for uniqueness is probabilistic. I give up.


s=3
for n in input():s+=pow(n,s,7**58)
print s==0x8b5ca8d0cea606d2b32726a79f01adf56f12aeb6e

Takes lists of integers as input, like [1,2,3,4,5].

The loop is meant to operate on the inputs in an annoying way, leaving a tower of sums and exponents. The idea is like discrete log, but with messy complication instead of mathematical simplicity. Maybe the compositeness of the of the modulus is a vulnerability, in which case I could make it something like 7**58+8.

I don't really know how I'd prove that my key is the only one, but the range of outputs is at least 10 times bigger than the range of inputs, so probably? Though maybe only a small fraction of potential outputs are achievable. I could always increase the number of digits at the cost of characters. I'll leave it up to you to decide what's fair.

Happy cracking!


0

Mathematica - 72

Version 2 of my script, with the same key as the one intended for my version 1.

This basically removes negative prime numbers for NextPrime.

f=Boole[(p=Abs[NextPrime/@#])-#=={18,31,6,9,2}&&BitXor@@#~Join~p==1000]&

Running:

f[{1,2,3,4,5}] (* => 0 *)

Assuming that I've correctly understood what your code does, I get several solutions of which the smallest is initial term 9244115, delta 25.
Peter Taylor

@PeterTaylor I can confirm that that one is valid.
Martin Ender

@PeterTaylor correct, another key is 1073743739, 1073886396, 1074029053, 1074171710, 1074314367
Tyilo

0

Python, 86 characters

a,b,c,d,e=input()
print 1if(a*c^b*e)*d==0xd5867e26a96897a2f80 and b^d==48891746 else 0

Enter the numbers like 1,2,3,4,5.

> python 36768.py <<< "1,2,3,4,5"
0
> python 36768.py <<< "[REDACTED]"
1

This isn't a valid submission; it accepts the input 1,0,1,63021563418517255630720,0.
Dennis

@Dennis Fixed. I hope it's valid now.
Snack

1
19960211, 31167202, 42374193, 53581184, 64788175
Dennis

@Dennis Correct and awesome. I think I'm very poor at math.
Snack

2
@Dennis, 63021563418517255630720 isn't a 32-bit number.
Peter Taylor


0

CJam, 37 characters (broken)

"煷➻捬渓类ⶥ땙ዶ꾫㞟姲̷ᐂ㵈禙鰳쥛忩蔃"2G#b[1q~]4G#b%!

Try it online.

How it works

See my new answer.

Example run

$ echo $LANG
en_US.UTF-8
$ base64 -d > flock.cjam <<< IueFt+Keu+aNrOa4k+exu+K2peuVmeGLtuq+q+Oen+Wnsu6AhMy34ZCC47WI56aZ6bCz7KWb5b+p6JSDIjJHI2JbMXF+XTRHI2IlIQ==
$ wc -m flock.cjam
37 flock.cjam
$ cjam flock.cjam < flock.secret; echo
1
$ cjam flock.cjam <<< "1 2 3 4 5"; echo
0

1
737262825 208413108 3974530688 3445680972 2916831257 works but isn't an arithmetic progression. Factored in 3 hours 20 minutes. 512-bit numbers were apparently doable in 72 hours for $75 on EC2 two years ago, so I think that would have been safe.
Peter Taylor

@PeterTaylor: That returns 1, but the last three integers are greater than MAX_INT, so it's not a valid key. That being said, 3 h 20 m is pretty impressive. The algorithm I was using took 16 hours for a 256-bit semiprime...
Dennis

I thought there must be some negative numbers in there somewhere because the deltas were almost right but not quite. I'll get on to it.
Peter Taylor

1
737262825 208413109 -320436607 -849286323 -1378136039
Peter Taylor

@PeterTaylor: That's the one. I hope the 512 bit version lasts longer.
Dennis

-2

C, 212 (Cracked)

This is the same idea as my previous submission, golfed more thoroughly, with a bug corrected that passed 0,0,0,0,0 (Thanks to Dennis for pointing out the bug). Compile with -std=c99.

#define L long long
p(L x){x=abs(x);for(L i=2;i<x;i++){if((x/i)*i==x)return 0;}return(x>1);}
f(a,b,c,d,e){char k[99];L m;sprintf(k,"%d%d%d%d%d",e,d,c,b,a);sscanf(k,"%lld",&m);
return p(a)&p(b)&p(c)&p(d)&p(e)&p(m);}

Any sequence (arithmetic or not) of negative primes will work. Two examples: -7 -37 -67 -97 -127, -157 -127 -97 -67 -37
Dennis

Yeah, my code is just riddled with bugs. The answer nitrous gave is along the lines of what I was looking for. But nice job pointing out the more obvious answers.
Orby
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.