我正在尝试将文件的内容通过管道传输到我制作的一个简单的 ASCII 对称加密程序。这是一个简单的程序,它从 STDIN 读取输入并对输入的每个字节添加或减去某个值 (224)。例如:如果第一个字节是 4,我们要加密,那么它变成 228。如果超过 255,程序只是执行一些模运算。
这是我用 cmd 得到的输出(test.txt 包含“这是一个测试”):
type .\test.txt | .\Crypt.exe --encrypt | .\Crypt.exe --decrypt
this is a test
Run Code Online (Sandbox Code Playgroud)
它也以另一种方式工作,因此它是一种对称加密算法
type .\test.txt | .\Crypt.exe --encrypt | .\Crypt.exe --decrypt
this is a test
Run Code Online (Sandbox Code Playgroud)
但是,PowerShell 上的行为是不同的。首先加密时,我得到:
type .\test.txt | .\Crypt.exe --decrypt | .\Crypt.exe --encrypt
this is a test
Run Code Online (Sandbox Code Playgroud)
这就是我首先解密时得到的:
可能是编码问题。提前致谢。
我正在用 C 做一个时间关键的应用程序。我想给一个变量赋值并同时在一个 while 循环中检查它的值,以便稍后在这个循环的主体中重用它。分配给变量的值由需要一些时间运行的函数返回。我知道我可以做这样的事情:
while (function_returning_int() <= foo) {
bar(function_returning_int());
}
Run Code Online (Sandbox Code Playgroud)
问题是这涉及调用同一个函数两次。我试着这样做:
while ((int thing = function_returning_int()) <= foo) {
bar(thing);
}
Run Code Online (Sandbox Code Playgroud)
它给了我一个错误。我不明白为什么因为赋值运算符 ( =) 返回分配的值。如何为变量赋值并在 while 循环中同时检查其值?