elgamal := proc(alpha, e, c, p)
    local calpha, n, y;
    calpha := alpha;
    n := e;
    y := 0;
    while n > 0 do
        if irem(n, 2, 'n') = 1 then
           y := addec(calpha, y, c, p):
        fi:
        calpha := addec(calpha, calpha, c, p):
    od:
    y;
end: