Advertisement
krot

zxor

Jun 8th, 2020
4,273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.40 KB | None | 0 0
  1. -export([zxor/2]).
  2.  
  3. zxor(Bin1,Bin2)->
  4. Len1=erlang:byte_size(Bin1),
  5. Len2=erlang:byte_size(Bin2),
  6.  
  7. {B1,B2}=  if
  8. (Len1<Len2)->{bin_pad(Bin1, Len2-Len1),Bin2};
  9. (Len1>Len2)->{Bin1,bin_pad(Bin2, Len1-Len2)};
  10. true ->{Bin1,Bin2}
  11. end,
  12. crypto:exor(B1,B2).
  13.  
  14. bin_pad(Bin,Len)->bin_pad(Bin,Len,<<16#00>>).
  15. bin_pad(Bin,0,_Ch)->Bin;
  16. bin_pad(Bin,Len,Ch)->
  17. L=binary:copy(Ch, Len),
  18. <<Bin/binary,L/binary>>.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement