分组密码的工作模式

了解一点密码学的都知道, 对称密码算法只有一个密钥, 加密解密都用同一个密钥. 最常见的AES就属于对称密码. 写成伪代码就是 密码 = AES加密(密钥, 明文). 但是到实际应用的代码的时候, 就会发现AES的加解密库还要求提供其他的一些参数: 其中工作模式(mode)是必填, 这参数是啥, 本文就讨论一下这个问题.

阅读全文

【Erlang】Erlang虚拟机的内部时钟

Erlang虚拟机可视为一个小型操作系统, 有自己的一套时钟系统, 与系统时间并不是完全一致的.

Erlang虚拟机时钟使用的是 erlang:now() 获取, 系统时间使用 os:timestamp() 获取. 格式是一样的三元组: {百万秒, 秒, 微秒}.

阅读全文

【Erl代码片段】简易的并行版lists:map/2

Joe在书上示范了一个并行化的lists:map:

pmap(F, L) ->
    S = self(),
    %% make_ref() returns a unique reference
    %% we'll match on this later
    Ref = erlang:make_ref(),
    Pids = map(fun(I) ->
                spawn(fun() -> do_f(S, Ref, F, I) end)
                end, L),

    %% gather the results
    gather(Pids, Ref).

do_f(Parent, Ref, F, I) ->
    Parent ! {self(), Ref, (catch F(I))}.

gather([Pid|T], Ref) ->
    receive
        {Pid, Ref, Ret} -> [Ret|gather(T, Ref)]
    end;
gather([], _) ->
    [].

阅读全文

(1 - 8)
Enter Press Enter to jump