-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_add_64.m
32 lines (31 loc) · 930 Bytes
/
mod_add_64.m
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
%
% modular addition for 2^64
%
function out = mod_add_64(a_hex, b_hex)
a = a_hex;
b = b_hex;
%
% split a, and b into left, and right parts in char string type
a_left = a(1:8);
a_right = a(9:16);
b_left = b(1:8);
b_right = b(9:16);
%
% convert a, and b into decimal type
a_left_dec = hex2dec(a_left);
a_right_dec = hex2dec(a_right);
b_left_dec = hex2dec(b_left);
b_right_dec = hex2dec(b_right);
%
%
a_b_right_dec = uint32(mod(a_right_dec + b_right_dec, 2^32));
a_b_right_qu = floor((a_right_dec + b_right_dec) / (2^32));
a_b_left_dec = uint32(mod(a_left_dec + b_left_dec + a_b_right_qu, 2^32));
%
a_b_left_hex = dec2hex(a_b_left_dec, 8);
a_b_right_hex = dec2hex(a_b_right_dec, 8);
%
% concatenate left and right string
a_b_hex = strcat(a_b_left_hex, a_b_right_hex);
out = a_b_hex;
return