Algorithms
第一周算法题:leetcode01
1 | Given an array of integers, return indices of the two numbers such that they add up to a specific target. |
思路:最开始想到的是暴力穷举,复杂度会高一点,仔细想了一下,可以使用哈希表记录每个元素对应的下标,然后查找target - a[i]。
1 | class Solution { |
Review
本周阅读英文文章:Making the Leap from Speech to Dialogue: The Challenge for Human to Machine Communication
spoken dialogue systems (SDS)语音对话系统
Right now these spoken dialogue systems (SDS) tends to be limited to a “command-based” approach, which can be seen with a number of recently introduced commercial implementations, like Apple’s Siri for the iOS, Amazon’s Echo/Alexa, and the social robot Jibo.
SDS最新发展由几种不同但相关的技术创建组成:
automatic speech recognition (ASR)自动语音识别
dialogue management (DM) 对话管理
text-to-speech (TTS) synthesis 文本到语音合成
Technique
OS:ubuntu16.04
生成一个密钥:
1 | openssl genrsa -out test.key 1024 |
-out指定生成文件的。需要注意的是这个文件包含了公钥和密钥两部分,也就是说这个文件即可用来加密也可以用来解密。1024是生成密钥的长度。
从test.key中提取公钥:
1 | openssl rsa -in test.key -pubout -out test_pub.key |
-in指定输入文件
-out指定提取生成公钥的文件名
至此,我们手上就有了一个公钥,一个私钥(包含公钥)。现在可以将用公钥来加密文件了。
创建hello.txt文件,查看内容
1 | $ hexdump -Cv hello.txt |
利用此前生成公钥加密文件:
1 | openssl rsautl -encrypt -in hello.txt -inkey test_pub.key -pubin -out hello.en |
-in指定要加密的文件
-inkey指定密钥
-pubin表明是用纯公钥文件加密
-out为加密后的文件
查看加密文件内容:
1 | $ hexdump -Cv hello.en |
解密文件:
1 | openssl rsautl -decrypt -in hello.en -inkey test.key -out hello.de |
-in指定被加密的文件
-inkey指定私钥文件
-out为解密后的文件
查看解密文件内容:
1 | $ hexdump -Cv hello.de |
关于hexdump:
1 | 可用参数 |
Share
《PythonCookBook》解压序列赋值给多个变量
任何的序列或者是可迭代对象可以通过一个简单的赋值语句解压并赋值给多个变量。 唯一的前提就是变量的数量必须跟序列元素的数量是一样的。如果变量个数和序列元素的个数不匹配,会产生一个异常。
1 | 'ACME', 50, 91.1, (2012, 12, 21) ] data = [ |
只想解压一部分,丢弃其他的值。对于这种情况Python并没有提供特殊的语法。但是可以使用任意变量名去占位,到时候丢掉这些变量就行了。
1 | 'ACME', 50, 91.1, (2012, 12, 21) ] data = [ |