bytearray.anubis
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
*Project* The Anubis Project
*Title* ByteArray Toolbox
*Copyright* Copyright (c) David René 2007.
*Created: 2007 01 23
*Author* David René
*Status* Released
*Overview*
read tools/basis.anubis
public define ByteArray
duplicate
(
ByteArray source
)=
extract(source, 0, length(source)).
define ByteArray
xor_ByteArray
(
ByteArray ba_a,
ByteArray ba_b,
ByteArray result,
Int32 count_down
)=
if count_down = 0 then
result
else
with value = truncate_to_word8(word8_to_int32(force_nth(count_down - 1, ba_a)):
word8_to_int32(force_nth(count_down - 1, ba_b))),
forget(put(result, count_down - 1, value));
xor_ByteArray(ba_a, ba_b, result, count_down -1).
/** make bitwise XOR of 2 ByteArray
*/
public define ByteArray
ByteArray a : ByteArray b =
with len_a = length(a),
len_b = length(b),
result_ba = if len_a > len_b then duplicate(a) else duplicate(b),
xor_ByteArray(a, b, result_ba, min(len_a, len_b)).
public define ByteArray
fill_ByteArray
(
ByteArray ba,
ByteArray fill
)=
with fill_len = length(fill), //length of given string
ba_len = length(ba), //length of given byte array
//if the fill ByteArray is more longer than given byte array, we just truncate it
if fill_len > ba_len then
extract(fill,0,ba_len)
//otherwise we extract the tail of given byte array and paste to string
else
fill + extract(ba, fill_len, ba_len).
public define ByteArray
fill_ByteArray
(
ByteArray ba,
String string
)=
with ba_string = to_byte_array(string), //convert string into byte array, for later manipulation
fill_ByteArray(ba, ba_string).