GithubHelp home page GithubHelp logo

des-golang-binary's Introduction

此算法是要求密钥和明文都是64位的二进制字符串(便于调试使用)。

des

数据加密标准(英语:Data Encryption Standard,缩写为 DES)是一种对称密钥加密块密码算法,1976年被美国联邦政府的国家标准局确定为联邦资料处理标准(FIPS),随后在国际上广泛流传开来。它基于使用56位密钥的对称算法。(来自wiki

项目结构

D:.
│─ main.go
└─ des
    │─ cipher_code.go
    │─ des.go
    │─ initial_replace.go
    │─ Iteration.go
    │─ reverse_replace.go
    └─ utils.go

des/

des.go

此文件中包含加密解密函数,为整个包对外的两个接口,用于对明文加密解密

cipher_code.go

此文件主要计算提供加解密过程中的数据,包括初始置换矩阵,选择置换1(PC-1),选择置换2(PC-2),子密钥,E扩展置换表,S盒置换表,P置换表以及逆序置换表。

子秘钥的生成:(秘钥调度)

首先,使用选择置换1(PC-1)从64位输入密钥中选出56位的密钥—剩下的8位要么直接丢弃,要么作为奇偶校验位。然后,56位分成两个28位的半密钥;每个半密钥接下来都被分别处理。在接下来的回次中,两个半密钥都被左移1或2位(由回次数决定),然后通过选择置换2(PC-2)产生48位的子密钥—每个半密钥24位。移位表明每个子密钥中使用了不同的位,每个位大致在16个子密钥中的14个出现。

initial_replace.go

加解密第一步:初始置换(IP)-- 将明文/密文经过一个8*8的矩阵变换来更改明文/密文的顺序

iteration.go

加解密第二步:费斯妥函数(F函数)

  • E扩张置换 -- 将32位(原始数据的一半)的明文/密文扩展到48位,其输出包括8个6位的数据
  • 与子密钥进行混合 -- 用异或操作将扩张的结果和一个子密钥进行混合。16个48位的子密钥——每个用于一个回次的F变换
  • S盒置换 -- 在与子密钥混合之后,块被分成8个6位的块,然后使用“S盒”,或称“置换盒”进行处理。8个S盒的每一个都使用以查找表方式提供的非线性的变换将它的6个输入位变成4个输出位。S盒提供了DES的核心安全性(如果没有S盒,密码会是线性的,很容易破解)。
  • P置换 -- 最后,S盒的32个输出位利用固定的置换,“P置换”进行重组。这个设计是为了将每个S盒的4位输出在下一回次的扩张后,使用4个不同的S盒进行处理。

reverse_replace.go

加解密最后一步:逆序置换(FP) -- 逆置换是初始置换的逆运算。从初始置换规则中可以看到,原始数据的第1位置换到了第40位,第2位置换到了第8位。则逆置换就是将第40位置换到第1位,第8位置换到第2位。

utils.go

该文件提供一些功能函数

main.go

提供使用该包的方法

【注】 解密过程中,除了子密钥顺序相反外,密钥调度的过程与加密完全相同。(即我们可以首先获得16个子秘钥,加密过程使用顺序的子秘钥,解密过程使用逆序的子秘钥)

【博客链接】 https://blog.csdn.net/liuyh73/article/details/83472521

des-golang-binary's People

Contributors

liuyh73 avatar

Watchers

 avatar

Forkers

zornh94

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.