救命!我忘记了我的密码!


24

救命!我刚刚登录Stack Exchange,但是忘记了密码!我需要一种方法来解决这个问题,然后再注销。

幸运的是,我是一名出色的黑客。我不仅能够找到密码的哈希,而且还发现了Stack Exchange的哈希算法!它采用每个数字的ASCII值乘以该数字的位置,然后将所有这些值相加。例如:

"135" -> 1*49 + 2*51 + 3*53 = 310

我记得我的密码是3位数字,每个字符是一个介于0到5(含0和5)之间的数字(这样它将与regex:匹配^[0-5]{3}$),但是仍然有太多的猜测可能性。我需要一个可以将哈希转换回潜在密码的程序,但是尽管是一名专业的黑客,但我无法编写代码来挽救生命!我可以手动编写这些测试:

input -> output
288   -> 000                      // lowest possible hash
290   -> 200, 010
298   -> 022, 050, 103, 131, 212, 240, 321, 402, 430, 511   
318   -> 555                      // highest possible hash

你们中的一个可以为我编写一个程序,该程序将散列并打印我可能使用的所有可能的密码吗?

输入将始终能够产生至少一个有效密码。只要可以清楚地标识字符串,就可以使用任何输出格式。我也不担心前导零,因此,如果可能的密码是001,我也将接受011

请帮助我避免被Stack Exchange拒之门外!

计分

这是,因此每种语言中最短的答案将获胜!


是不是1Ascii值49代替了48
LiefdeWen

1
@LordFarquaad测试用例看起来不错,但示例应该是"135" -> 1*49 + 2*51 + 3*53 = 310
LiefdeWen

1
必须用逗号定界(逗号后面也可以有一个或多个空格也是可以的)为什么使用限制性输出格式?我们通常允许使用灵活的格式
Luis Mendo

1
这里通常说的是“允许任何输出格式,只要可以清楚地识别字符串”。或允许使用任何非数字分隔符。如果您更改了它,请在答复中用注释通知当前的答复者
Luis Mendo

1
@FelipeNardiBatista是的,前导零是可选的。我记得我用了3位数字,所以如果我看到54我可以算出前面的零。
法夸德勋爵(Lord Farquaad)'17年

Answers:



9

C113108字节

f(int h){int i=47,j,k;while(++i<54)for(j=47;++j<54)for(k=47;++k<54;)if(h==i+j+j+k*3)printf("%c%c%c",i,j,k);}

唯一看到输出的含义是,输出的格式为:200010

所有密码均以无限制符的3位数字表示。


2
嘿,我能看懂代码!与果冻之类的很好的对比。+1以使用经典语言。:)
通配符

8

果冻,16 字节

Ṿ€Oæ.J
6Ḷṗ3Ç⁼¥Ðf

单数链接,返回数字列表。

在线尝试!

怎么样?

Ṿ€Oæ.J - Link 1, hash: list of integers (the digits of a password)
Ṿ€     - unevaluate €ach (giving a list of characters)
  O    - cast to ordinals (Ṿ€O could actually be replaced with +48 too)
     J - range of length (i.e. [1,2,3] in all use-cases)
   æ.  - dot product

6Ḷṗ3Ç⁼¥Ðf - Main link: number, n
6Ḷ        - lowered range of 6 = [0,1,2,3,4,5]
  ṗ3      - Cartesian power with 3 = [[0,0,0],[0,0,1],...,[5,5,5]] (all passwords)
       Ðf - filter keep if:
      ¥   -   last two links as a dyad (right implicitly n):
    Ç     -     call last link (1) as a monad
     ⁼    -     equals right?


4

MATL,20字节

'0':'5'3Z^t3:*!si=Y)

在线尝试!

说明

'0':'5'   % Push inclusive range from '0' to '5', that is, '012345'
3Z^       % Cartesian power with exponent 3. Each Cartesian tuple is a row
t         % Duplicate
3:        % Push [1 2 3]
*         % Multiply element-wise with broadcast
!s        % Sum of each row
i         % Input number
=         % Logical mask of values that equal the input
Y)        % Use as logical index into the rows of the matrix. Implicit display



2

C#(.NET Core)133131125123字节

n=>{int i,j,k;for(i=48;i<54;++i)for(j=48;j<54;++j)for(k=48;k<54;++k)if(i+j*2+k*3==n)Console.Write($"{i%48}{j%48}{k%48},");}

在线尝试!


之前,我曾给出过更详尽的建议,但并没有使其正常工作。现在,我的简单优化是使用Console.Write($"{i%48}{j%48}{k%48},");输出而不是构建返回值,并删除if语句周围不必要的括号以节省8个字节。
卡米尔·德拉科里

我之前尝试过该选项,但Lambda需要返回值。卸下支架仍然可以。谢谢:)
jkelm

如果将lambda定义为Func<int,string>,则需要返回值,但是如果将其定义为,Action<int>则它不希望返回值。
卡米尔·德拉卡里

没意识到!我既不熟悉C#,也不喜欢打高尔夫球,但是当我无事可做时,我决定尝试一下。再次感谢您的提示。我非常赞赏他们。
jkelm

1
如果您使用C#charintC#之间的歧义,则可以像char在第一个循环中那样声明迭代变量,并且仍然像简化Console.Write()句子一样完全进行哈希计算。因此,您可以获得正确的119字节解决方案。在线尝试!
查理

2

木炭,33字节

F⁶F⁶F⁶¿⁼⁺℅Iι⁺×℅Iκ²×℅Iλ³Iθ«IιIκIλ⸿

在线尝试!

与其他答案相似的方法:从0到5循环三次,计算哈希值,如果迭代变量与输入哈希值一致,则打印迭代变量的状态。

链接到详细版本


2

CJam26 25字节

-1字节感谢Challenger5

{:H;6Zm*{s:i3,:).*:+H=},}

匿名块期望在堆栈上有哈希(作为整数),并将结果保留在堆栈上(作为字符串列表)。

在线尝试!

说明

:H;    e# Store the hash in H.
6Zm*   e# 3rd Cartesian power of [0 1 2 3 4 5].
{      e# For each tuple in the power:
 s     e#  Stringify the tuple.
 :i    e#  Get the code point of each digit.
 3,:)  e#  Push [1 2 3].
 .*    e#  Element-wise multiplication of the two lists.
 :+    e#  Sum the result.
 H=    e#  Check if it's equal to the hash.
},     e# Filter the tuples to only ones for which this block gave a truthy result.

@LordFarquaad哦,呃...我什至没有看到它,所以我想那很幸运
Business Cat

{:H;6Zm*{s:i3,:).*:+H=},}短1个字节。它使用过滤器中的数字字符串而不是数字来使用m*的自动范围。
硕果累累

@ Challenger5很好,谢谢!
Business Cat

2

Java,162字节

static void f(int n){for(int i=48;i<54;i++){for(int j=48;j<54;j++){for(int k=48;k<54;k++){if(i+j*2+k*3==n)System.out.println((char)i+""+(char)j+""+(char)k);}}}}

2

JavaScript(Firefox 30-57),72个字节

n=>[for(i of s="012345")for(j of s)for(k of s)if(n-i-j*2-k*3==288)i+j+k]


1

QBIC,40个字节

[0,5|[0,5|[0,5|~a+b+b+c+c+c+288=:\?a,b,c

说明

[0,5|                Make a FOR loop run through the possible digits for pos 1, called a
[0,5|                Loop for #2, b
[0,5|                Loop for #3, c
                     Calculate the hash by taking a once, b twice and c thrice, 
                     and raising all to their ASCII codepoints
 a+b+b+c+c+c+288       
~               =:   IF thta is euqal to the given hash (read from cmd line)
\?a,b,c              THEN print the digits
                     (the IF and the FOR loops are auto-closed by QBIC)

1

R67 62 61字节

-5个字节,得益于Jarko Dubbeldam

b=t(t(expand.grid(rep(list(0:5),3))));b[b%*%1:3==scan()-288,]

在线尝试!

从中读取数字stdin; 返回一个矩阵,其中的行是字符。

它以矩阵格式(b)生成所有可能的三位数,计算矩阵乘积b * [1,2,3],获取b匹配的行(288从输入中减去1*48+2*28+3*48)并返回它们。


1
t(t(m))as.matrix(m)
JAD
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.