ascii

有关ascii码的hill加解密

人走茶凉 提交于 2020-01-13 03:50:39
hill加解密的原理实际上就是利用可逆矩阵,将明文矩阵和加密矩阵进行计算得到密文,在接收端利用密文和加密矩阵的逆进行计算再得到明文。[加密矩阵][明文矩阵]%256=[密文矩阵],[加密矩阵的逆][密文矩阵]%256=[明文矩阵]。 本次实验是将一串明文英文字符串(可包含空格)作为输入,根据加密矩阵的阶数来构建对应的明文矩阵(明文转换为ascii码),然后与加密矩阵进行计算,对256取余再对密文进行转义输出成加密字符。解密时,先计算加密矩阵的逆,调用python的numpy包进行计算,结果输出都是小数,需要转换为分数,得到分子和分母,目的是为了方便计算小数对整数取余。 小数对整数取余,先转换为分数。在python里面调用fractions,v = fractions.Fraction(mat[j][i]).limit_denominator()#小数转分数,v.denominator和v.numerato#分别获取分子和分母。 假设(a/b)%256取余:(a/b)%256=x得到a(%256)=bx,继续得到bx=256k+a,即x=(256k+a)/b。把k从0开始取,直到x计算得到整数为之。35/3对256取余得到97。 实验输入和输出为: 请输入加密位数(-1结束):9 请输入明文:wo ai ni zhongguo! 明文矩阵: [[119, 97, 110, 122,

How to handle unicode character sequences in C/C++?

我只是一个虾纸丫 提交于 2020-01-12 07:10:23
问题 What are the more portable and clean ways to handle unicode character sequences in C and C++ ? Moreover, how to: -Read unicode strings -Convert unicode strings to ASCII to save some bytes (if the user only inputs ASCII) -Print unicode strings Should I use the environment too ? I've read about LC_CTYPE for example, should I care about it as a developer ? 回答1: What are the more portable and clean ways to handle unicode character sequences in C and C++ ? Have all strings in your program be UTF-8

Graphviz and ascii output

二次信任 提交于 2020-01-11 15:25:12
问题 Is it possible to draw ASCII diagram using Graphviz? Something like that: digraph { this -> is this -> a a -> test } Gives undesired result. Instead, I would like to get similar ASCII representation: this / \ is a | test How to draw ascii diagrams from dot-files format? 回答1: If you are not perl averse, graph-easy (and the associated Graph::Easy package) can do exactly that: http://search.cpan.org/~tels/Graph-Easy/ http://search.cpan.org/~tels/Graph-Easy/bin/graph-easy On Mac you can install

Sql Server函数全解(一)字符串函数

二次信任 提交于 2020-01-11 15:06:57
字符串函数用于对字符和二进制字符进行各种操作 1.ASCII()函数  ASCII(character_expression)函数用于返回字符串表达式中最左侧的ASCII代码值。参数character_expression必须是一个char或varchar类型的字符串表达式。   eg: select ASCII('s'),ASCII('sql'),ASCII('1'); 执行结果如图: 字符's'的ASCII值为115,所以第一行和第二行返回结果相同,对于第三条语句中的纯数字的字符串,可以不用单引号括起来。 2.CHAR()函数  CHAR(integer_expression)函数将整数类型的ASCII值转换为对应的字符,integer_expression是一个介于0~255之间的整数。如果该整数表达式不在此范围内,将返回null值。 eg: select CHAR(115),CHAR(49); 可以看到,这里返回的值与ASCII函数的返回值正好相反. 3.LEFT()函数   LEFT(character_expression,integer_expression)函数返回字符串左边开始指定个数的字符串、字符或者二进制数据表达式。character_expression是字符串表达式,可以是常量,变量或字段。integer_expression为整数,指定character

Mixed ascii and unicode output from script - how to get command to output all as ascii?

老子叫甜甜 提交于 2020-01-11 13:14:13
问题 I have a script which is run from a service which is built using C++ and is not built using unicode. This program runs the script below and strangely, the output from the script running the wmic qfe list line seems to output as unicode. Sample output below. Here is the script: @echo off echo This text is output as standard - no spacing between characters >>C:\log.txt REM this one is output with 1 space between characters wmic qfe list >>C:\log.txt echo This text is also output as standard -

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)

瘦欲@ 提交于 2020-01-11 09:56:41
python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0x?? in position 1: ordinal not in range(128),python没办法处理非ascii编码的,此时需要自己设置将python的默认编码,一般设置为utf8的编码格式。 解决方法: 1、在程序文件中以下三句 import sys reload ( sys ) sys . setdefaultencoding ( 'utf8' ) 2、在Python的Lib\site-packages文件夹下新建一个sitecustomize.py文件,内容为: #coding=utf8 import sys reload ( sys ) sys . setdefaultencoding ( 'utf8' ) 3、在命令行修改,仅本会话有效: 1)通过>>>sys.getdefaultencoding()查看当前编码(若报错,先执行>>>import sys >>>reload(sys)); 2)通过>>>sys.setdefaultencoding(‘utf8’)设置编码 重启Python解释器,发现编码已被设置为utf8。 文章资料源于网络

python基础二

给你一囗甜甜゛ 提交于 2020-01-10 11:05:27
一. 格式化输出 现有一练习需求,问用户的姓名、年龄、工作、爱好 ,然后打印成以下格式 ------------ info of 太白金星 ----------- Name : 太白金星 Age : 22 job : Teacher Hobbie : girl ------------- end ---------------- 你怎么实现呢?你会发现,用字符拼接的方式还难实现这种格式的输出,所以一起来学一下新姿势 只需要把要打印的格式先准备好, 由于里面的 一些信息是需要用户输入的,你没办法预设知道,因此可以先放置个占位符,再把字符串里的占位符与外部的变量做个映射关系就好啦 name = input ( "Name:" ) age = input ( "Age:" ) job = input ( "Job:" ) hobbie = input ( "Hobbie:" ) info = ''' ------------ info of %s ----------- #这里的每个%s就是一个占位符,本行的代表 后面拓号里的 name Name : %s #代表 name Age : %s #代表 age job : %s #代表 job Hobbie: %s #代表 hobbie ------------- end ----------------- ''' %( name ,

ASCII编码表

时光总嘲笑我的痴心妄想 提交于 2020-01-10 03:30:03
American Standard Code for Information Interchange , 美国标准 信息交换代码 . 在计算机中,所有的数据在存储和运算时都要使用二进制数表示 , a 、 b 、 c 、 d 这样的 52 个字母(包括大写)、以及 0 、 1 等数字还有一些常用的符号 , 在计算机中存储时也要使用二进制数来表示,而具体用哪些二进制数字表示哪个符号,当然每个人都可以约定自己的一套(这就叫编码),而大家如果要想互相通信而不造成混乱,那么大家就必须使用相同的编码规则,于是美国有关的标准化组织就出台了 ASCII 编码,统一规定了上述常用符号用哪些二进制数来表示。 数字 0-9 对应 ASCII 编码十进制为 48-57, 字母 a-z 对应 ASCII 编码十进制为 97-122 ,字母 A-Z 对应 ASCII 编码十进制为 65-90。 来源: CSDN 作者: little-stars 链接: https://blog.csdn.net/weixin_41874888/article/details/103910813

How to change the bytes in a file?

江枫思渺然 提交于 2020-01-10 03:26:08
问题 I'm making a encryption program and I need to open file in binary mode to access non-ascii and non-printable characters, I need to check if character from a file is letter, number, symbol or unprintable character. That means I have to check 1 by 1 if bytes (when they are decoded to ascii) match any of these characters: {^9,dzEV=Q4ciT+/s};fnq3BFh% #2!k7>YSU<GyD\I]|OC_e.W0M~ua-jR5lv1wA`@8t*xr'K"[P)&b:g$p(mX6Ho?JNZL I think I could encode these characters above to binary and then compare them

Credit Card validation: can Card Name contain non-ASCII characters?

社会主义新天地 提交于 2020-01-09 19:06:20
问题 Can the Card Name (i.e. the cardholder name, not the card type) contain non-ASCII characters? Example: "JOSÉ GONZÁLEZ". 回答1: The character set that is used does not allow for diacritics. In brief, it only allows uppercase ASCII characters. The restriction ultimately comes from the historical way in which banking cards encode data onto the magnetic stripe (as defined in ISO 7811). The data is encoded in a 7 bits per character format known as ITU-T.50 The cardholder name is encoded with up to