CN115412232A - 一种加密和解密的实现方法 - Google Patents

一种加密和解密的实现方法 Download PDF

Info

Publication number
CN115412232A
CN115412232A CN202210941036.4A CN202210941036A CN115412232A CN 115412232 A CN115412232 A CN 115412232A CN 202210941036 A CN202210941036 A CN 202210941036A CN 115412232 A CN115412232 A CN 115412232A
Authority
CN
China
Prior art keywords
block
0xff
data
length
decryption
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210941036.4A
Other languages
English (en)
Inventor
李春敏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Wallta Industrial Co ltd
Original Assignee
Shenzhen Wallta Industrial Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Wallta Industrial Co ltd filed Critical Shenzhen Wallta Industrial Co ltd
Priority to CN202210941036.4A priority Critical patent/CN115412232A/zh
Publication of CN115412232A publication Critical patent/CN115412232A/zh
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/08Key distribution or management, e.g. generation, sharing or updating, of cryptographic keys or passwords
    • H04L9/0861Generation of secret information including derivation or calculation of cryptographic keys or passwords
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/04Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks
    • H04L63/0428Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks wherein the data content is protected, e.g. by encrypting or encapsulating the payload

Abstract

一种对称加解密的方法,可以有效防止暴力破解。

Description

一种加密和解密的实现方法
技术领域
本发明涉及计算机及信息技术领域。本发明提供的是一种加密和解密的实现方法。
背景技术
当前人们在使用计算传送文件时,文件内容经常被黑客和目标人员盗取,在这种情况下往往会造成非常大的经济损失。本发明提供一种对计算机文件内容进行加密和解密的方法,以提升网络上传送文件的安全性。
发明内容
本发明提供的加解密算法,其加密的表达形式为y=Encode(x,l,k),解密的表达形式为x= Decode(y,l,k,L)。
上述表达式中不同部分的含义如下:
Encode代表加密,Decode代表解密;
y指加密后的内容即密文;x指加密前的内容即明文;l指分块的长度,为偶数;k指密钥,L指明文的长度。
Encode加密运算步骤如下:
1、将原始明文按照顺序,分为指定长度的块,这些块满足如下条件:
块的长度由用户指定,但块的长度须为偶数字节;
如果最后一个块没有达到用户指定的长度,则采用随机数填充;
2、将分割后,每个块中的内容进行顺序反转;
3、第一个块的顺序反转处理
第一个字节和最后一个字节调换;
第二个字节和倒数第二个字节调换;
以此类推完成第一个块的处理。
4、其他块同样做反转处理;
5、将反转后的内容再次连接成为一个连续的内存区域;
6、将连接后内存区域中的每个位(bit)取反,即原来为0的位置改为1,原来为1的位置改为0;
7、将取反后的内存再次分块,此次分块按照密钥长度进行;
8、块的异或运算
第一个块的第一个字节和密钥的第一个字节做异或运算;
第一个块的第二个字节和密钥的第二个字节做异或运算;
以此类推完成第一个块的处理。
9、其他块同样做异或运算;
10、将处理完成的数据连接成为一个连续的内存区域;
11、对这块内存的数据采用Base58的方式进行编码输出,即为加密内容。
Decode解密运算步骤如下:
1、将输入的Base58解密为原始数据;
2、将Base58解密后的数据,按照密钥的长度进行分块;
3、块的异或运算
第一个块的第一个字节和密钥的第一个字节做异或运算;
第一个块的第二个字节和密钥的第二个字节做异或运算;
以此类推完成第一个块的处理。
4、其他块同样做异或运算;
5、将异或运算后的数据连接成为一个连续的内存区域;
6、将连接后内存区域中的每个位(bit)取反,即原来为0的位置改为1,原来为1的位置改为0;
7、按照分块长度,将取反后的数据再次进行分块;
8、第一个块的顺序反转处理
第一个字节和最后一个字节调换;
第二个字节和倒数第二个字节调换;
以此类推完成第一个块的处理。
9、其他块同样做反转处理;
10、将反转后的内容再次连接成为一个连续的内存区域;
11、按照明文长度,将最后多余的字节丢弃,剩余内容即为明文内容。
加密实施举例
1.原始数据:
明文x:0x00 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa 0xbb0xcc 0xdd 0xee 0xff 0x12 0x34 0x56;
分块长度4;
密钥为:0xff 0xff 0xff
内容长度:19
2.按照步骤进行加密:
a)分块:
0x00 0x11 0x22 0x33
0x44 0x55 0x66 0x77
0x88 0x99 0xaa 0xbb
0xcc 0xdd 0xee 0xff
0x12 0x34 0x56
b)最后一块的长度小于分块长度,所以填充随机数0x78,填充后的结果如下:
0x00 0x11 0x22 0x33
0x44 0x55 0x66 0x77
0x88 0x99 0xaa 0xbb
0xcc 0xdd 0xee 0xff
0x12 0x34 0x56 0x78
c)每块进行反转,反转后的结果
0x33 0x22 0x11 0x00
0x77 0x66 0x55 0x44
0xbb 0xaa 0x99 0x88
0xff 0xee 0xdd 0xcc
0x78 0x56 0x34 0x12
d)对每个位(bit)取反,取反后的结果
0xcc 0xdd 0xee 0xff
0x88 0x99 0xaa 0xbb
0x44 0x55 0x66 0x77
0x00 0x11 0x22 0x33
0x87 0xa9 0xcb 0xed
e)将去饭后的内容连接成为一个连续的空间,如下
0xcc 0xdd 0xee 0xff 0x88 0x99 0xaa 0xbb 0x44 0x55 0x66 0x77 0x00 0x110x22 0x33 0x87 0xa9 0xcb 0xed
f)按照密钥的长度进行分块,如下
0xcc 0xdd 0xee
0xff 0x88 0x99
0xaa 0xbb 0x44
0x55 0x66 0x77
0x00 0x11 0x22
0x33 0x87 0xa9
0xcb 0xed
g)使用密钥进行异或运算,结果如下
0x33 0x22 0x11
0x00 0x77 0x66
0x55 0x44 0xbb
0xaa 0x99 0x88
0xff 0xee 0xdd
0xcc 0x78 0x56
0x34 0x12
h)将异或后的数据连接成一个完成的内存空间:
0x33 0x22 0x11 0x00 0x77 0x66 0x55 0x44 0xbb 0xaa 0x99 0x88 0xff 0xee0xdd 0xcc 0x78 0x56 0x34 0x12
i)将连续内存的数据进行Base58编码后的结果为,也就是加密的输出数据
iKQs8RSWR1sVawReqAdFTM5zpZF
解密实施举例
1.原始数据:
密文y:iKQs8RSWR1sVawReqAdFTM5zpZF
分块长度4
密钥为:0xff 0xff 0xff
内容长度:19
2.按照步骤进行解密:
a)将连续内存的数据进行Base58解码后的结果为
0x33 0x22 0x 11 0x00 0x77 0x66 0x55 0x44 0xbb 0xaa 0x99 0x88 0xff0xee 0xdd 0xcc 0x78 0x56 0x34 0x12
b)对Base58解密后的数据进行分块,分块长度为密钥长度,分块结果如下:
0x33 0x22 0x11
0x00 0x77 0x66
0x55 0x44 0xbb
0xaa 0x99 0x88
0xff 0xee 0xdd
0xcc 0x78 0x56
0x34 0x12
c)使用密钥,对每个块进行异或运算,运算结果如下:
0xcc 0xdd 0xee
0xff 0x88 0x99
0xaa 0xbb 0x44
0x55 0x66 0x77
0x00 0x11 0x22
0x33 0x87 0xa9
0xcb 0xed
d)对异或运算的结果取反,结果如下:
0x33 0x22 0x 11 0x00 0x77 0x66 0x55 0x44 0xbb 0xaa 0x99 0x88 0xff0xee 0xdd 0xcc 0x78 0x56 0x34 0x12
e)对数据重新进行分块,结果如下:
0x33 0x22 0x11 0x00
0x77 0x66 0x55 0x44
0xbb 0xaa 0x99 0x88
0xff 0xee 0xdd 0xcc
0x78 0x56 0x34 0x12
f)对结果顺序进行反转,结果如下:
0x00 0x11 0x22 0x33
0x44 0x55 0x66 0x77
0x88 0x99 0xaa 0xbb
0xcc 0xdd 0xee 0xff
0x12 0x34 0x56 0x78
g)将数据块连接为一个连续的存储空间,结果如下:
0x00 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa 0xbb 0xcc 0xdd0xee 0xff 0x12 0x34 0x56 0x78
h)根据明文长度,修改最后一个字节,即得到原始的明文:
0x00 0x 11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa 0xbb 0xcc0xdd 0xee 0xff 0x 12 0x34 0x56
应用场景
在通过网络发送文件前首先对文件进行加密。然后通过网络发送文件内容。
然后告知接收端文件长度、分块长度以及密钥,对端即可进行解密。

Claims (4)

1.一种对称加解密的算法,其加密输出为Base58编码格式的数据,解密输入为Base58编码格式的数据。
2.根据权利要求1所述,加密和解密过程需要对数据分块进行反转。
3.根据权利要求1所述,加密和解密过程需要对数据分块进行异或运算。
4.根据权利2和3所述,数据分块反转和数据分块异或的块长度不一样。
CN202210941036.4A 2022-08-05 2022-08-05 一种加密和解密的实现方法 Pending CN115412232A (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210941036.4A CN115412232A (zh) 2022-08-05 2022-08-05 一种加密和解密的实现方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210941036.4A CN115412232A (zh) 2022-08-05 2022-08-05 一种加密和解密的实现方法

Publications (1)

Publication Number Publication Date
CN115412232A true CN115412232A (zh) 2022-11-29

Family

ID=84159340

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210941036.4A Pending CN115412232A (zh) 2022-08-05 2022-08-05 一种加密和解密的实现方法

Country Status (1)

Country Link
CN (1) CN115412232A (zh)

Similar Documents

Publication Publication Date Title
CN1993922B (zh) 流密码组合系统和方法
US8121294B2 (en) System and method for a derivation function for key per page
WO2003021863A1 (en) Non-algebraic method of encryption and decryption
CN108270550B (zh) 一种基于sm4算法的安全高效的白盒实现方法及装置
KR20180081559A (ko) 암호화 동작을 위한 키 시퀀스 생성
CN113098675B (zh) 基于多项式完全同态的二进制数据加密系统及方法
JPH01261689A (ja) データ秘匿方式
JP2008035305A (ja) 暗号化方法及びデータ秘匿方法
WO2015166701A1 (ja) 暗号化方法、プログラム、および、システム
EP1416664A2 (en) Data encryption method
CN115412232A (zh) 一种加密和解密的实现方法
CN102340688A (zh) 一种图像序列的加密、解密方法
CN114205144A (zh) 数据传输方法、装置、设备、存储介质及程序产品
Chen et al. An image encryption algorithm based on SM4 and Base64
Shakir et al. Image encryption using lorenz chaotic system
JPH05249891A (ja) 暗号処理装置およびこれを用いる暗号処理方法
KR101824315B1 (ko) 데이터 암호화 방법 및 장치, 및 데이터 복호화 방법 및 장치
US20220417012A1 (en) Method for performing cryptographic operations in a processing device, corresponding processing device and computer program product
Jasuja et al. Crypto-compression system: an integrated approach using stream cipher cryptography and entropy encoding
Blaise et al. An Understanding and Perspectives of End-To-End Encryption
Kumar et al. An image encryption technique to remove the drawback of the one-dimensional scrambling method of image encryption
Malhotra et al. Genetic symmetric key generation for idea
Wadi et al. Binary decomposition-based Image cipher algorithm with flexible method for key construction
CN113268707B (zh) 一种基于行编码的密文协方差矩阵计算方法
CN201252558Y (zh) 基于广义信息域的高级加密系统

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination