小编Joh*_*mBF的帖子

如何纠正TypeError:必须在散列之前编码Unicode对象?

我有这个错误:

Traceback (most recent call last):
  File "python_md5_cracker.py", line 27, in <module>
  m.update(line)
TypeError: Unicode-objects must be encoded before hashing
Run Code Online (Sandbox Code Playgroud)

当我尝试在Python 3.2.2中执行此代码时:

import hashlib, sys
m = hashlib.md5()
hash = ""
hash_file = input("What is the file name in which the hash resides?  ")
wordlist = input("What is your wordlist?  (Enter the file name)  ")
try:
  hashdocument = open(hash_file, "r")
except IOError:
  print("Invalid file.")
  raw_input()
  sys.exit()
else:
  hash = hashdocument.readline()
  hash = hash.replace("\n", "")

try:
  wordlistfile = open(wordlist, …
Run Code Online (Sandbox Code Playgroud)

python unicode syntax-error hashlib python-3.x

256
推荐指数
9
解决办法
27万
查看次数

Python print语句"语法错误:语法无效"

为什么Python print在第9行的简单语句中给出了语法错误?

import hashlib, sys
m = hashlib.md5()
hash = ""
hash_file = raw_input("What is the file name in which the hash resides?  ")
wordlist = raw_input("What is your wordlist?  (Enter the file name)  ")
try:
    hashdocument = open(hash_file,"r")
except IOError:
    print "Invalid file."    # Syntax error: invalid syntax
    raw_input()
    sys.exit()
else:
    hash = hashdocument.readline()
    hash = hash.replace("\n","")
Run Code Online (Sandbox Code Playgroud)

Python的版本是:

Python 3.2.2 (default, Sep  4 2011, 09:07:29) [MSC v.1500 64 bit (AMD64)] on win
32
Run Code Online (Sandbox Code Playgroud)

python syntax syntax-error python-3.x

50
推荐指数
2
解决办法
19万
查看次数

如何确定.EXE是否具有命令行选项?

假设您有一个.EXE,并且您想要检查它是否具有命令行选项.如何知道.EXE是否具备此功能.在我的情况下,我知道Nir Sofers WebBrowserPassView.exe能够通过cmd.exe和WebBrowserPassView.exe/stext output.txt启动它.但是我怎么能知道我不知道呢?

executable command-line exe command-line-arguments

46
推荐指数
4
解决办法
13万
查看次数

在bash中,如何设置返回码?

我想设置一次返回值,使其进入while循环:

#!/bin/bash
while [ $? -eq 1 ]
do
#do something until it returns 0    
done
Run Code Online (Sandbox Code Playgroud)

为了使这个工作,我需要$? = 1在开始时设置,但这不起作用.

error-handling bash return-value exit-code

29
推荐指数
6
解决办法
5万
查看次数

如何在Bash/Grep中删除单引号?

我想用grep搜索一个如下所示的字符串:

something ~* 'bla'
Run Code Online (Sandbox Code Playgroud)

我试过这个,但是shell删除了单引号argh ..

grep -i '"something ~* '[:alnum:]'"' /var/log/syslog
Run Code Online (Sandbox Code Playgroud)

什么是正确的搜索?

linux bash grep escaping

26
推荐指数
2
解决办法
4万
查看次数

如何使用批处理或PowerShell脚本循环访问CSV文件?

我有一个包含两个不同列的CSV文件,一个包含PC名称,另一个包含MAC地址,如下所示:

PCxxxx 00-11-22-33-44-55
...
...
Run Code Online (Sandbox Code Playgroud)

这些值应放在以下CLI命令中:

wdsutil /Set-Device /Device:PCxxxx /ID:00-11-22-33-44-55
Run Code Online (Sandbox Code Playgroud)

现在因为它们中有大约200个,我想自动化它.

有兴趣的话,可以批量做吗?这会很复杂,对吧?我想到了数组,但不认为可以批量执行此操作.

也许使用PowerShell它会更容易一些.

powershell cmd batch-file

7
推荐指数
1
解决办法
2万
查看次数

我必须包含哪个头文件才能在内核源文件中获取printk()?

比方说,我想用printk()内部arch/x86/boot/string.c编译内核之前.我必须包含哪个头文件,以便链接器知道在哪里找到printk()?我尝试过#include <linux/kernel.h>,#include <linux/printk.h>但在make bzImage告诉我链接器找不到时总是出错printk:

arch/x86/boot/compressed/string.o: In function `memcmp`:
string.c:(.text+0x19): undefined reference to `printk`
Run Code Online (Sandbox Code Playgroud)

c linux gcc compiler-errors linux-kernel

6
推荐指数
1
解决办法
1万
查看次数

如何迭代unicode字符并使用printf在C屏幕上打印它们?

我想迭代所有(至少16位)unicode字符并用C在屏幕上打印它们.

我知道有关于SO的相关问题,但它们并没有解决printfC中的问题,但这是我想要实现的,如果它毕竟是可能的.我认为应该可能有一个我不知道的技巧.

既然我想使用printf,我想到了这样的事情:

for (int i = 0x0000; i <= 0xffff; i++) {

    //then somehow increment the string
    char str[] = "\u25A1\n";
    printf("%s", str);

    char str[] = "\u25A2\n";
    printf("%s", str);

    char str[] = "\u25A3\n";
    printf("%s", str);

    ...

}
Run Code Online (Sandbox Code Playgroud)

但是这里增加unicode代码点有点问题\u25A1.我知道它本身不可能,因为有些字符\u0000不可打印,编译器说不.但除此之外,我怎么能从十六进制0000增加到ffff并打印字符printf.

c unicode printf

5
推荐指数
2
解决办法
4619
查看次数

如何找出linux内核响应IRQ需要多长时间?

我怎么能测量linux内核响应IRQ需要多长时间?

我可以触发键盘IRQ并开始计算时间但是如何找出ISR何时完成?

c linux kernel interrupt linux-kernel

5
推荐指数
0
解决办法
157
查看次数

为什么“echo l &gt; /proc/sysrq-trigger”调用跟踪输出总是相似的?

根据官方 kernel.org 文档 echo l > /proc/sysrq-trigger应该给我所有 CPU 的当前调用跟踪。但是当我这样做几次并查看dmesg之后,调用跟踪看起来完全相似。这是为什么?

linux call backtrace linux-kernel sysctl

4
推荐指数
1
解决办法
5078
查看次数