Siguiendo con la serie de funciones destinadas a crear nuestro pequeño servidor, vamos a ver una función para descifrar una cadena de texto cifrada en base64. Esta función nos sera útil cuando implementemos la identificación de usuarios, es un sistema muy simple, así que solo nos dará un nivel de seguridad básico aunque suficiente para este proyecto.
const Alphabet64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; function decode64(s: string): string; var i, j, k: integer; w: word; begin result := ''; w := 0; j := 0; for i := 1 to length(s) do begin k := pos(s[i], Alphabet64); if k > 0 then begin w := w shl 6; w := w + k - 1; inc(j, 6); if j >= 8 then begin dec(j, 8); result := result + chr(lo(w shr j)); w := w mod (1 shl j); end; end else exit; end; end;