hackertyper.net


11

介绍

hackertyper.net是一个网站,它通过在您输入时以每输入3个字符的速率将Linux内核的加密部分中的复杂代码输出到屏幕上来模拟“黑客攻击”(正如媒体所描绘的那样)。

挑战

您的程序/函数应该接受文件作为命令行参数,对文件路径进行硬编码,或者接受文本(文件中的内容)作为命令行或函数参数,并模仿hackertyper.net对于通过STDIN或同等功能接收到的每个字符,通过从文件向屏幕输出3个字符(STDOUT或同等功能)。

一旦达到EOF,程序应再次从文件开头开始输出字符(自动换行)。

眼镜

为简单起见,您可以假定STDIN已设置为无缓冲区和无回显模式,即等到用户按下Enter键,然后再将输入传递给程序并且不显示键入的字符。

该文件可以包含换行符,而输入不包含换行符

有关用C语言编写的小示例(非高尔夫球),以演示其工作原理,请参见this

不需要绿色文本和黑色背景。

输入和输出示例

文件:

#include <stdio.h>
int main() { }

输入:

hello world

输出:

#include <stdio.h>
int main() { }

文件:

hello

输入:

hello world

输出:

hellohellohellohellohellohellohel

1
1.是否允许使用函数(将两个字符串作为参数并返回另一个字符串)?2.您的规范要求每个输入输出三个字符,但是示例仅为每个输入输出一个字符。
门把手

1
@Doorknob 1.是,并且2.这是一个错误,已修复。
Majora320 '16

我们是否必须将文件信息作为文件接收,还是可以通过函数参数或等效参数接收该信息?如果需要,该文件的名称是什么?它是位于远离我们脚本的特定目录中,还是与我们脚本在同一目录中?
R. Kap


3
奖金不好。再加上很少有人会受到惩罚,称其为“奖金”令人困惑。
CalculatorFeline

Answers:


7

果冻,4 字节

ẋ3ṁ@

在线尝试!

这个怎么运作

ẋ3ṁ@    Main link. Arguments: s (input string), t (file string)

ẋ3      Repeat s three times.
  ṁ@    Mold; reshape t like the previous result.
        This repeats the elements of t over and over until the length matches that
        of s repeated thrice.

我一直想知道“霉菌”是什么意思……
Leaky Nun

18
@KennyLau我认为这意味着该丢掉面包了。
Alex A.

4

J,7个字节

$~(3*#)

接受两个参数,即要重复的文本和用户的输入文本。

用法

输入文本的格式,表示加入的位置,并且LF是换行符。

   f =: $~(3*#)
   ('#include <stdio.h>', LF, 'int main() { }') f 'hello world'
#include <stdio.h>
int main() { }
   'hello' f 'hello world'
hellohellohellohellohellohellohel

在线尝试。(tryj.tk)


4

果冻,9个字节

⁴L×3
ẋ¢ḣ¢

在线尝试!

⁴L×3     Define nilad as ¢:

 L       length of
⁴        second argument
  ×3     tripled


ẋ¢ḣ¢     Main chain:

         the first argument (implicit)
ẋ        repeated
 ¢       ¢ many times
  ḣ¢     then get the first ¢ characters of it.

2
我想你对丹尼斯的回答有点“果冻”?
丹尼斯·范·吉尔斯

果冻是邪恶的..
CalculatorFeline


3

JavaScript(ES6),40个字节

(s,t)=>s.repeat(l=t.length*3).slice(0,l)

哪里s是数据字符串,t是用户字符串。假设s是非空的,并重复其l次数以确保其长度至少为,l以便它可以返回第一个l字符,其中l的长度是的三倍t


3

Haskell,25个字节

第一个参数是“类型化”,第二个参数显示

(.cycle).take.(3*).length

或非无点的,以(可能)更好的可读性:

h a=take(3*length a).cycle

什么cycle
CalculatorFeline

@CatsAreFluffy cycle获取列表并无限重复。例如cycle "hi" == "hihihihi..
Michael Klein

你考虑过了$吗?
CalculatorFeline

@CatsAreFluffy我不确定在哪里使用它,您在想什么?
Michael Klein

3

Python 3.5、77 65 63字节:

lambda g,f:''.join((g*len(f))[i:i+3]for i in range(0,len(f)*3,3))

很简单。一个带有两个参数的匿名函数,第一个参数是“文件”(g),第二个参数是用户输入的字符(f)。然后这将创建一个生成器g,其中包含每个中的三个字符,通过i依次为每个中的i+3字符进行索引可以找到生成器g,其中i的范围在0=>(length of f)*3。最后,它返回生成器中的每个对象,这些对象被合并为一个大字符串。您可以通过向其分配变量来调用此函数,然后调用包装在print()表达式中的变量。因此,如果函数的名称为q,则将像print(q(<byte array here>))

在线尝试!(代表)


2

05AB1E,7个字节

码:

3×g©×®£

说明:

3×        # Multiply the input string three times.
  g       # Take the length.
   ©      # Copy that to the register.
    ×     # Multiply by the second input.
     ®    # Retrieve the length from the register.
      £   # Only keep [0:length * 3] from the new string.

在线尝试!



2

Ruby,39个字节

在Ruby中,$<从命令行参数中提供的文件中读取内容,而不是从中读取$stdin。(如果忘记提供文件,则会得到空白输出,因为它从$stdinin 读取所有内容$<.read,因此STDIN.read.size将为0。)

$><<($<.read*s=3*STDIN.read.size)[0,s]
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.