You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
7.0 KiB
C

1 year ago
#pragma execution_character_set("utf-8")
//DES<45><EFBFBD><E3B7A8>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/*
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>DES<EFBFBD>
ԭ<EFBFBD>ģ<EFBFBD>Matthew Fischer
DES( Data Encryption Standard)<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1977<EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>56λ<EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>64λ<EFBFBD><EFBFBD><EFBFBD>ݵķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DES<EFBFBD><EFBFBD>Ա<EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD><EFBFBD>ܵij<EFBFBD><EFBFBD>ϡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>UNIX<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DES<EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBF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D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD>õ<EFBFBD>56λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD>У<EFBFBD><EFBFBD><EFBFBD>żУ<EFBFBD><EFBFBD>λ<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Permuted Choice 1 (PC-1)
57 49 41 33 25 17 9
1 58 50 42 34 26 18
10 2 59 51 43 35 27
19 11 3 60 52 44 36
63 55 47 39 31 23 15
7 62 54 46 38 30 22
14 6 61 53 45 37 29
21 13 5 28 20 12 4
1-2-2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>28λ<EFBFBD><EFBFBD>ΪC[0]<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>28λ<EFBFBD><EFBFBD>ΪD[0]<EFBFBD><EFBFBD>
1-2-3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>16<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼI=1<EFBFBD><EFBFBD>
1-2-3-1<EFBFBD><EFBFBD>ͬʱ<EFBFBD><EFBFBD>C[I]<EFBFBD><EFBFBD>D[I]<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1λ<EFBFBD><EFBFBD>2λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Iֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>
I<EFBFBD><EFBFBD> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1
1-2-3-2<EFBFBD><EFBFBD><EFBFBD><EFBFBD>C[I]D[I]<EFBFBD><EFBFBD>Ϊһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><EFBFBD><EFBFBD>PC-2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>48λ<EFBFBD><EFBFBD>K[I]
<EFBFBD><EFBFBD>
Permuted Choice 2 (PC-2)
14 17 11 24 1 5
3 28 15 6 21 10
23 19 12 4 26 8
16 7 27 20 13 2
41 52 31 37 47 55
30 40 51 45 33 48
44 49 39 56 34 53
46 42 50 36 29 32
1-2-3-3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1-2-3-1<EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD>ִ<EFBFBD>У<EFBFBD>ֱ<EFBFBD><EFBFBD>K[16]<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɡ<EFBFBD>
2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>64λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2-1<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>64λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD>Ȳ<EFBFBD><EFBFBD><EFBFBD>64λ<EFBFBD><EFBFBD>Ӧ<EFBFBD>ý<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չΪ64λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2-2<EFBFBD><EFBFBD><EFBFBD><EFBFBD>64λ<EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><EFBFBD>±<EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<EFBFBD><EFBFBD>
Initial Permutation (IP)
58 50 42 34 26 18 10 2
60 52 44 36 28 20 12 4
62 54 46 38 30 22 14 6
64 56 48 40 32 24 16 8
57 49 41 33 25 17 9 1
59 51 43 35 27 19 11 3
61 53 45 37 29 21 13 5
63 55 47 39 31 23 15 7
2-3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>32λ<EFBFBD><EFBFBD>ΪL[0]<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>32λ<EFBFBD><EFBFBD>ΪR[0]<EFBFBD><EFBFBD>
2-4<EFBFBD><EFBFBD><EFBFBD><EFBFBD>16<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD>ʼI=1<EFBFBD><EFBFBD>
2-4-1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>32λ<EFBFBD><EFBFBD>R[I-1]<EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><EFBFBD><EFBFBD>E<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չΪ48λ<EFBFBD><EFBFBD>E[I-1]
Expansion (E)
32 1 2 3 4 5
4 5 6 7 8 9
8 9 10 11 12 13
12 13 14 15 16 17
16 17 18 19 20 21
20 21 22 23 24 25
24 25 26 27 28 29
28 29 30 31 32 1
2-4-2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>E[I-1]<EFBFBD><EFBFBD>K[I]<EFBFBD><EFBFBD><EFBFBD><EFBFBD>E[I-1] XOR K[I]
2-4-3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ8<EFBFBD><EFBFBD>6λ<EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD>֣<EFBFBD><EFBFBD><EFBFBD>1λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>6λ<EFBFBD><EFBFBD>ΪB[1]<EFBFBD><EFBFBD><EFBFBD><EFBFBD>7λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>12λ<EFBFBD><EFBFBD>ΪB[2]<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><EFBFBD><EFBFBD>43λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>48λ<EFBFBD><EFBFBD>ΪB[8]<EFBFBD><EFBFBD>
2-4-4<EFBFBD><EFBFBD><EFBFBD><EFBFBD>S<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>B[J]<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼJ=1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>S<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBF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2 15
13 8 10 1 3 15 4 2 11 6 7 12 0 5 14 9
S[3]
10 0 9 14 6 3 15 5 1 13 12 7 11 4 2 8
13 7 0 9 3 4 6 10 2 8 5 14 12 11 15 1
13 6 4 9 8 15 3 0 11 1 2 12 5 10 14 7
1 10 13 0 6 9 8 7 4 15 14 3 11 5 2 12
S[4]
7 13 14 3 0 6 9 10 1 2 8 5 11 12 4 15
13 8 11 5 6 15 0 3 4 7 2 12 1 10 14 9
10 6 9 0 12 11 7 13 15 1 3 14 5 2 8 4
3 15 0 6 10 1 13 8 9 4 5 11 12 7 2 14
S[5]
2 12 4 1 7 10 11 6 8 5 3 15 13 0 14 9
14 11 2 12 4 7 13 1 5 0 15 10 3 9 8 6
4 2 1 11 10 13 7 8 15 9 12 5 6 3 0 14
11 8 12 7 1 14 2 13 6 15 0 9 10 4 5 3
S[6]
12 1 10 15 9 2 6 8 0 13 3 4 14 7 5 11
10 15 4 2 7 12 9 5 6 1 13 14 0 11 3 8
9 14 15 5 2 8 12 3 7 0 4 10 1 13 11 6
4 3 2 12 9 5 15 10 11 14 1 7 6 0 8 13
S[7]
4 11 2 14 15 0 8 13 3 12 9 7 5 10 6 1
13 0 11 7 4 9 1 10 14 3 5 12 2 15 8 6
1 4 11 13 12 3 7 14 10 15 6 8 0 5 9 2
6 11 13 8 1 4 10 7 9 5 0 15 14 2 3 12
S[8]
13 2 8 4 6 15 11 1 10 9 3 14 5 0 12 7
1 15 13 8 10 3 7 4 12 5 6 11 0 14 9 2
7 11 4 1 9 12 14 2 0 6 10 13 15 3 5 8
2 1 14 7 4 10 8 13 15 12 9 0 3 5 6 11
2-4-4-4<EFBFBD><EFBFBD><EFBFBD><EFBFBD>2-4-4-1<EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD>ִ<EFBFBD>У<EFBFBD>ֱ<EFBFBD><EFBFBD>B[8]<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɡ<E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EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Final Permutation (IP**-1)
40 8 48 16 56 24 64 32
39 7 47 15 55 23 63 31
38 6 46 14 54 22 62 30
37 5 45 13 53 21 61 29
36 4 44 12 52 20 60 28
35 3 43 11 51 19 59 27
34 2 42 10 50 18 58 26
33 1 41 9 49 17 57 25
*/
#ifndef _ALGORITHM_DES_H
#define _ALGORITHM_DES_H
#include <string>
//<2F><><EFBFBD>ܽ<EFBFBD><DCBD><EFBFBD>
typedef enum
{
DT_ENCRYPT = 0, //<2F><><EFBFBD><EFBFBD>
DT_DECRYPT //<2F><><EFBFBD><EFBFBD>
}DES_TYPE;
//DES<45><EFBFBD><E3B7A8>ģʽ
typedef enum
{
DM_ECB = 0, //ECBģʽ
DM_CBC //CBCģʽ
}DES_MODE;
//Pad<61><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
typedef enum
{
PT_ISO_1 = 0, //ISO_1<5F><31><EFBFBD><EFBFBD><E4A3BA><EFBFBD>ݳ<EFBFBD><DDB3>Ȳ<EFBFBD><C8B2><EFBFBD>8<EFBFBD><38><EFBFBD>صı<D8B5><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0x00<30><30><EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD>Ϊ8<CEAA><38><EFBFBD>صı<D8B5><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD><38>0x00
PT_ISO_2, //ISO_2<5F><32><EFBFBD><EFBFBD><E4A3BA><EFBFBD>ݳ<EFBFBD><DDB3>Ȳ<EFBFBD><C8B2><EFBFBD>8<EFBFBD><38><EFBFBD>صı<D8B5><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0x80,0x00..<2E><><EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD>Ϊ8<CEAA><38><EFBFBD>صı<D8B5><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0x80,0x00..0x00
PT_PKCS_7 //PKCS7<53><37><EFBFBD><EFBFBD><E4A3BA><EFBFBD>ݳ<EFBFBD><DDB3>ȳ<EFBFBD>8<EFBFBD><38><EFBFBD><EFBFBD>Ϊn,<2C><>(8-n)<29><><EFBFBD><EFBFBD>Ϊ8<CEAA>ı<EFBFBD><C4B1><EFBFBD>
}PAD_TYPE;
class DES
{
public:
//DES();
DES(DES_MODE mode = DM_CBC, PAD_TYPE pad_type = PT_ISO_1);
virtual ~DES();
typedef bool (*PSubKey)[16][48];
bool Encrypt(char *in, unsigned int inLen, const char *key, unsigned char keyLen, char *out);
bool Decrypt(char *in, unsigned int inLen, const char *key, unsigned char keyLen, char *out);
/*******************************************************************
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: RunPad
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> bType :<EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>PAD<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
In :<EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>ָ<EFBFBD><EFBFBD>
Out :<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
datalen :<EFBFBD><EFBFBD><EFBFBD>ݵij<EFBFBD><EFBFBD><EFBFBD>
padlen :(in,out)<EFBFBD><EFBFBD><EFBFBD><EFBFBD>buffer<EFBFBD>ij<EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ ˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> bool :<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
*******************************************************************/
bool RunPad(const char* in,unsigned int inLen,char* out,unsigned int &padlen);
bool RunPad(std::string &in);
/*******************************************************************
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: RunDes
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ִ<EFBFBD><EFBFBD>DES<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> bType :<EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ENCRYPT<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DECRYPT
bMode :ģʽ<EFBFBD><EFBFBD>ECB,CBC
In :<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD>ָ<EFBFBD><EFBFBD>
Out :<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
datalen :<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD>ȣ<EFBFBD>ͬʱOut<EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>СӦ<EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><EFBFBD>ߵ<EFBFBD><EFBFBD><EFBFBD>datalen
Key :<EFBFBD><EFBFBD>Կ(<EFBFBD><EFBFBD>Ϊ8λ,16λ,24λ)֧<EFBFBD><EFBFBD>3<EFBFBD><EFBFBD>Կ
keylen :<EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>24λ<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD>ü<EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ ˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> bool :<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳɹ<EFBFBD>
*******************************************************************/
bool RunDes(DES_TYPE desType, const char* in,unsigned int inLen, const char* key,const unsigned char keyLen, char* out);
private:
//<2F><><EFBFBD><EFBFBD><E3B2A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><D4BF>SubKey<65><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void SetSubKey(PSubKey pSubKey, const char Key[8]);
//DES<45><53>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>
void Des(char Out[8], const char In[8], const PSubKey pSubKey, DES_TYPE desType);
private:
DES_MODE m_mode;
PAD_TYPE m_pad_type;
};
/*
std::string des_encrypt(std::string in, std::string key);
std::string des_decrypt(std::string in, std::string key);
*/
#endif