当前位置:网站首页>Software College of Shandong University Project Training - Innovation Training - network security range experimental platform (XVII)
Software College of Shandong University Project Training - Innovation Training - network security range experimental platform (XVII)
2022-06-10 16:17:00 【Scrambled eggs with tomatoes without eggs!】
Catalog
3.2 RC4 Password encryption and decryption
Preface : This blog is mainly recorded in the security tools Rot13 encryption 、RC4 Implementation of encryption and decryption .
One 、Rot13 password
1.1 brief introduction
ROT13( Turn around 13 position ) Is a simple replacement cipher algorithm . It's a way to hide gossip in English online forums 、 Witticism 、 Puzzles, answers and tools for swearing , The purpose is to escape a glimpse of the moderator or .ROT13 It is also a variant of the Caesar code developed in ancient Rome .ROT13 It is the reverse of itself , namely : To restore to the original text, just use the same algorithm , Therefore, the same operation can be used for encryption and decryption . This algorithm does not provide real security in cryptography , Therefore, it should not be used for purposes requiring preservation . It is often used as a typical example of weak encryption .
application ROT13 To a piece of text just check the alphabetical order and replace it in 13 The corresponding letter after bit , If there is a need to exceed it, go back to 26 Just start with an English letter .A Switch to N、B Switch to O、 And so on to M Switch to Z, Then the serial inversion :N Switch to A、O Switch to B、 Last Z Switch to M( As shown in the figure ). Only those characters that appear in English letters are affected ; Numbers 、 Symbol 、 White space characters and all other characters remain the same . The case of the replaced letters remains unchanged .
1.2 Code implementation
<template>
<br>
<br>
<el-card shadow="always" style="text-align: center; margin-right: 100px;margin-left: 100px;height: 700px">
<!-- title -->
<el-row>
<el-col :span="8">
</el-col>
<el-col :span="8">
<div style="font-size: x-large;background-color: darkgreen;color:white;margin: 5px;">
Rot13 Online encryption and decryption
</div>
<el-button style="text-align: right" size="small" icon="el-icon-thumb">
<el-link href="https://blog.csdn.net/qq_17046291/article/details/80306580?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165459051316782184695260%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=165459051316782184695260&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-80306580-null-null.142^v11^pc_search_result_control_group,157^v13^new_style1&utm_term=Rot13&spm=1018.2226.3001.4187"
target="_blank"
style="font-size: 20px;color: darkgreen"
> What is? Rot13?
</el-link>
</el-button>
</el-col>
<el-col :span="8">
</el-col>
</el-row>
<!-- Input box -->
<div class="el-common-layout">
<div class="text-area" style="margin: 10px">
<!-- <textarea v-model="textdata" placeholder=" Please enter the encoded string or the string to be decoded ">-->
<!-- </textarea>-->
<el-input
v-model="textdata"
type="textarea"
placeholder=" Please enter the content to be encrypted and decrypted "
style="width: 600px;font-size: 20px;margin: 10px;"
:rows=5
/>
</div>
</div>
<!-- Encryption / decryption button -->
<el-button @click="encode(textdata)" type="info" style="margin: 20px;margin-bottom: 0px;">EnCrypto</el-button>
<el-button @click="decode(textdata)" type="info">DeCrypto</el-button>
<!-- Result area -->
<el-card style="width: 40%;height: 20%;margin-left: 30%;margin-top: 3%">
<h2 style="text-align: left"> encryption / Decryption result :</h2>
<el-input
v-model="myresult"
type="textarea"
placeholder=""
style="font-size: 20px"
disabled
:rows=5
/>
<!-- <p>{
{ myresult }}</p>-->
</el-card>
</el-card>
</template>
// Rot13 encryption
@GetMapping("/encrypto")
public Result encrypto(@RequestParam() String Text) throws UnsupportedEncodingException {
System.out.println(" Plaintext :"+Text);
Rot13 rot13=new Rot13();
String encryStr = rot13.cipher(Text);
System.out.println(" Encrypted string :"+encryStr);
return Result.success(encryStr);
}
// Rot13 Decrypt
@GetMapping("/decrypto")
public Result decrypto(@RequestParam() String Text) throws UnsupportedEncodingException {
System.out.println(" Ciphertext :"+Text);
Rot13 rot13=new Rot13();
String decryStr = rot13.cipher(Text);
System.out.println(" Decrypted string :"+decryStr);
return Result.success(decryStr);
}
static {
final char[] lookup1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
final char[] lookup2 = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm".toCharArray();
Map m = new HashMap();
for (int i = 0; i < lookup1.length; i++) {
m.put(lookup1[i], lookup2[i]);
}
map = Collections.unmodifiableMap(m);
}
/**
* ROT-13 Algorithm .
*
* @param inStr
* @return
*/
public static String cipher(final String inStr) {
char[] arr = inStr.toCharArray();
StringBuilder sb = new StringBuilder(arr.length);
for (char c : arr) {
Character out = (Character) map.get(c);
if (out == null) {
sb.append(c);
} else {
sb.append(out);
}
}
return sb.toString();
}Two 、RC4 password
2.1 brief introduction
RC4( come from Rivest Cipher 4 Abbreviation ) It's a stream encryption algorithm , Key length is variable . It uses the same key for encryption and decryption , Therefore, it also belongs to symmetric encryption algorithm .RC4 Is Wired Equivalent encryption (WEP) The encryption algorithm used in , It used to be TLS One of the available algorithms .
RC4 Algorithm characteristics :
(1)、 The algorithm is simple and easy to implement by software , Fast encryption , High security ;
(2)、 Key length is variable , It's usually used 256 Bytes .
Introducing RC4 Before the principle of algorithm , Let's first look at some key variables in the algorithm :
● Key stream :RC4 The key of the algorithm is to generate the corresponding key stream according to plaintext and key , The length of the key stream corresponds to the length of the plaintext , That is to say, the length of expository text is 500 byte , So the key stream is also 500 byte . Of course , The ciphertext generated by encryption is also 500 byte , Because ciphertext No i byte = In the first place i byte ^ Key stream number i byte .
● State vector S: The length is 256,S[0],S[1]…S[255]. Each unit is a byte , Any time the algorithm runs ,S It all includes 0-255 Of 8 Permutation and combination of bits , It's just that the position of the value changes ;
● Temporary vector T: The length is also 256, Each unit is also a byte . If the length of the key is 256 byte , Just assign the value of the key to T, otherwise , Assign each byte of the key to in turn T;
● secret key K: The length is 1-256 byte , Note the length of the key keylen And plaintext length 、 The length of the key stream does not necessarily matter , Usually the length of the key is interesting 16 byte (128 The bit )
2.2 Code implementation
<!--RC4 encryption -->
<template>
<br>
<br>
<el-card shadow="always" style="text-align: center; margin-right: 100px;margin-left: 100px;height: 700px">
<!-- title -->
<el-row>
<el-col :span="8">
</el-col>
<el-col :span="8">
<div style="font-size: x-large;background-color: darkgreen;color:white;margin: 5px;">
RC4 Online encoding and decoding
</div>
<el-button style="text-align: right" size="small" icon="el-icon-thumb">
<el-link href="https://blog.csdn.net/wangningzk123/article/details/108294288?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165451738016782395393911%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=165451738016782395393911&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_click~default-2-108294288-null-null.142^v11^pc_search_result_control_group,157^v13^control&utm_term=RC4&spm=1018.2226.3001.4187"
target="_blank"
style="font-size: 20px;color: darkgreen"
> What is? RC4?
</el-link>
</el-button>
</el-col>
<el-col :span="8">
</el-col>
</el-row>
<!-- Input box -->
<div class="el-common-layout">
<div class="text-area" style="margin: 10px">
<!-- <textarea v-model="textdata" placeholder=" Please enter the encoded string or the string to be decoded ">-->
<!-- </textarea>-->
<el-input
v-model="textdata"
type="textarea"
placeholder=" Please enter the content to be encrypted and decrypted "
style="width: 600px;font-size: 20px;margin: 10px;"
:rows=5
/>
<el-input
v-model="key"
type="textarea"
placeholder=" Please enter the key "
style="width: 600px;font-size: 20px;margin: 10px;"
:rows=5
/>
</div>
</div>
<!-- Encryption / decryption button -->
<el-button @click="encode(textdata,key)" type="info" style="margin: 20px;margin-bottom: 0px;">EnCrypto</el-button>
<el-button @click="decode(textdata,key)" type="info">DeCrypto</el-button>
<!-- Result area -->
<el-card style="width: 40%;height: 20%;margin-left: 30%;margin-top: 3%">
<h2 style="text-align: left"> encryption / Decryption result :</h2>
<el-input
v-model="myresult"
type="textarea"
placeholder=""
style="font-size: 20px"
disabled
:rows=5
/>
<!-- <p>{
{ myresult }}</p>-->
</el-card>
</el-card>
</template>
// RC4 encryption
@GetMapping("/encrypto")
public Result encrypto(@RequestParam() String clearText, @RequestParam() String Key) throws UnsupportedEncodingException {
System.out.println(" Plaintext :"+clearText);
RC4 rc4=new RC4();
String encryStr = rc4.encryRC4String(clearText, Key,"UTF-8");
System.out.println(" Encrypted string :"+encryStr);
return Result.success(encryStr);
}
// RC4 Decrypt
@GetMapping("/decrypto")
public Result decrypto(@RequestParam() String cipherText,@RequestParam() String Key) throws UnsupportedEncodingException {
System.out.println(" Ciphertext :"+cipherText);
RC4 rc4=new RC4();
String decryStr = rc4.decryRC4(cipherText, Key,"UTF-8");
System.out.println(" Decrypted string :"+decryStr);
return Result.success(decryStr);
}
/**
* RC4 encryption , Hash the encrypted data
* @param data Data that needs to be encrypted
* @param key Encryption key
* @param chartSet Encoding mode
* @return Return encrypted data
* @throws UnsupportedEncodingException
*/
public static String encryRC4String(String data, String key, String chartSet) throws UnsupportedEncodingException {
if (data == null || key == null) {
return null;
}
return bytesToHex(encryRC4Byte(data, key, chartSet));
}
/**
* RC4 encryption , The encrypted byte data
* @param data Data that needs to be encrypted
* @param key Encryption key
* @param chartSet Encoding mode
* @return Return encrypted data
* @throws UnsupportedEncodingException
*/
public static byte[] encryRC4Byte(String data, String key, String chartSet) throws UnsupportedEncodingException {
if (data == null || key == null) {
return null;
}
if (chartSet == null || chartSet.isEmpty()) {
byte bData[] = data.getBytes();
return RC4Base(bData, key);
} else {
byte bData[] = data.getBytes(chartSet);
return RC4Base(bData, key);
}
} /**
* RC4 Decrypt
* @param data Data that needs to be decrypted
* @param key Encryption key
* @param chartSet Encoding mode
* @return Return decrypted data
* @throws UnsupportedEncodingException
*/
public static String decryRC4(String data, String key,String chartSet) throws UnsupportedEncodingException {
if (data == null || key == null) {
return null;
}
return new String(RC4Base(hexToByte(data), key),chartSet);
}
/**
* RC4 Encryption initialization key
* @param aKey
* @return
*/
private static byte[] initKey(String aKey) {
byte[] bkey = aKey.getBytes();
byte state[] = new byte[256];
for (int i = 0; i < 256; i++) {
state[i] = (byte) i;
}
int index1 = 0;
int index2 = 0;
if (bkey.length == 0) {
return null;
}
for (int i = 0; i < 256; i++) {
index2 = ((bkey[index1] & 0xff) + (state[i] & 0xff) + index2) & 0xff;
byte tmp = state[i];
state[i] = state[index2];
state[index2] = tmp;
index1 = (index1 + 1) % bkey.length;
}
return state;
}
3、 ... and 、 Show the effect
3.1 Rot13 encryption

3.2 RC4 Password encryption and decryption

边栏推荐
- 【第七节 函数的作用】
- 2D human posture estimation for posture estimation - simple baseline (SBL)
- Rk3308-- firmware compilation
- C # game prototype character map dual movement
- Smart home (3) competitive product analysis of Intelligent Interaction
- How does the wireless communication module help the intelligent UAV build the "Internet of things in the air"?
- Diagram of the quarterly report of station B: the revenue is RMB 5.1 billion, with a year-on-year increase of 30% and nearly 300million monthly active users
- RK3308 按键Key与LED灯
- This and object prototypes
- Query-Convert QuickView是灰掉的解决办法(转)_SAP刘梦
猜你喜欢

Driver development and abnormal analysis of "technical dry goods" industrial touch screen (serial)

Anba cv2fs/cv22fs obtained ASIL C chip function safety certification, surpassing the level of similar chips in the market

Join operation cases in the map phase of MapReduce

RGB颜色空间、色调、饱和度、亮度、HSV颜色空间详解

Application scenario introduction of nixie tube driver chip + voice chip, wt588e02b-24ss

这几个垂直类小众导航网站,你绝对不会想错过

Cube 技术解读 | Cube 渲染设计的前世今生

RK3308 按键Key与LED灯

Comply with medical reform and actively layout -- insight into the development of high-value medical consumables under the background of centralized purchase 2022

Diagram of the quarterly report of station B: the revenue is RMB 5.1 billion, with a year-on-year increase of 30% and nearly 300million monthly active users
随机推荐
[section 7 function]
PV operation daily question - black and white chess question (variant)
姿态估计之2D人体姿态估计 - Human Pose Regression with Residual Log-likelihood Estimation(RLE)[仅链接]
【无标题】
Diagram of the quarterly report of station B: the revenue is RMB 5.1 billion, with a year-on-year increase of 30% and nearly 300million monthly active users
MapReduce之Word Count案例代码实现
Jerry's ble abnormal power consumption [chapter]
Interpretation of cube technology | past and present life of cube Rendering Design
Online document collaboration tool is the first step to improve work efficiency
Driver development and abnormal analysis of "technical dry goods" industrial touch screen (serial)
torch.nn.utils.rnn.pad_sequence()详解【Pytorch入门手册】
Anba cv2fs/cv22fs obtained ASIL C chip function safety certification, surpassing the level of similar chips in the market
Baidu open source ice-ba installation and operation summary
我用 MATLAB 复刻了抖音爆火小游戏 苹果蛇
MapReduce之Map阶段的join操作案例
Unified certification center oauth2 certification pit
Missing setjarbyclass() when running MapReduce task. No class found
[sans titre]
uniapp中常用到的方法(部分) - 时间戳问题及富文本解析图片问题
Application scenario introduction of nixie tube driver chip + voice chip, wt588e02b-24ss