API
Core
Text
IO / OS
Net
Encoding
Crypto
Compress / image / math
Database
External packages
UI
API
#crypto/des
Xu 0.8.8 API
import: #crypto/des
counts: 2 fns, 5 methods, 2 types, 1 consts, 0 ifaces
DES / 3DES-EDE single block.
const block_size
Purpose
DES and Triple DES (FIPS 46-3) aligned with `crypto/des` NewCipher / NewTripleDESCipher. Single 8-byte block encrypt/decrypt. Permutation tables use lsb bit indices. IP/FP/E/P/S-box are parsed once in new_cipher and read by field index in crypt_block Not constant-time. Value `8`.
Parameters
none
struct Cipher
pub struct Cipher {
pub subkeys []int
}
Purpose
Public struct `Cipher`.
Parameters
subkeys []int field ([]int)
struct TripleCipher
pub struct TripleCipher {
pub k1 []int
pub k2 []int
pub k3 []int
}
Purpose
Public struct `TripleCipher`.
Parameters
k1 []int field ([]int)
k2 []int field ([]int)
k3 []int field ([]int)
new_cipher
pub fn new_cipher(key &string ) Cipher
Purpose
Construct cipher. Throws on failure.
Parameters
key &string key (borrowed; caller keeps it; type &string)
Returns
Cipher — a value of this type
(&Cipher) block_size
pub fn (c &Cipher) block_size() int
Purpose
Method on `&Cipher`: block size.
Parameters
c &Cipher receiver &Cipher (borrow)
Returns
int — a value of this type
(&Cipher) encrypt
pub fn (c &Cipher) encrypt(src &string ) string
Purpose
Method on `&Cipher`: encrypt.
Parameters
c &Cipher receiver &Cipher (borrow)
src &string source (borrowed; caller keeps it; type &string)
Returns
string — result string
(&Cipher) decrypt
pub fn (c &Cipher) decrypt(src &string ) string
Purpose
Method on `&Cipher`: decrypt.
Parameters
c &Cipher receiver &Cipher (borrow)
src &string source (borrowed; caller keeps it; type &string)
Returns
string — result string
new_triple_cipher
pub fn new_triple_cipher(key &string ) TripleCipher
Purpose
Construct triple cipher. Throws on failure.
Parameters
key &string key (borrowed; caller keeps it; type &string)
Returns
TripleCipher — a value of this type
(&TripleCipher) encrypt
pub fn (c &TripleCipher) encrypt(src &string ) string
Purpose
Method on `&TripleCipher`: encrypt.
Parameters
c &TripleCipher receiver &TripleCipher (borrow)
src &string source (borrowed; caller keeps it; type &string)
Returns
string — result string
(&TripleCipher) decrypt
pub fn (c &TripleCipher) decrypt(src &string ) string
Purpose
Method on `&TripleCipher`: decrypt.
Parameters
c &TripleCipher receiver &TripleCipher (borrow)
src &string source (borrowed; caller keeps it; type &string)
Returns
string — result string