v2 / vlib / crypto / rc4 / rc4_test.v
36 lines · 27 sloc · 687 bytes · a4b8768146ed5a5d712747f51f84fafabec149a6
Raw
1// Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved.
2// Use of this source code is governed by an MIT license
3// that can be found in the LICENSE file.
4import crypto.cipher
5import crypto.rc4
6
7struct StreamCipher {
8 cipher cipher.Stream
9}
10
11fn test_cfb_stream_cipher() ! {
12 key := 'tthisisourrc4key'.bytes()
13 c := rc4.new_cipher(key)!
14
15 s := StreamCipher{
16 cipher: c
17 }
18}
19
20fn test_crypto_rc4() {
21 key := 'tthisisourrc4key'.bytes()
22
23 mut c := rc4.new_cipher(key) or {
24 println(err)
25 return
26 }
27
28 mut src := 'toencrypt'.bytes()
29
30 // src & dst same, encrypt in place
31 c.xor_key_stream(mut src, src) // encrypt data
32
33 c.reset()
34
35 assert src.hex() == '189a39a91aea8afa65'
36}
37