Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

AGUNG IFB

defmodule Caesar_cipher do
  defp set_map(map, range, key) do
    org = Enum.map(range, &List.to_string [&1])
    {a, b} = Enum.split(org, key)
    Enum.zip(org, b ++ a) |> Enum.into(map)
  end
 
  def encode(text, key) do
    map = Map.new |> set_map(?a..?z, key) |> set_map(?A..?Z, key)
    String.graphemes(text) |> Enum.map_join(fn c -> Map.get(map, c, c) end)
  end
end
 
text = "AGUNG FHAJAR FADILAH IF-B CIANJUR"
key = 5
IO.puts "ASSALAMUALAIKUM WR.WB"
IO.puts "Original:  #{text}"
IO.puts "Encrypted: #{enc = Caesar_cipher.encode(text, key)}"
IO.puts "Decrypted: #{Caesar_cipher.encode(enc, -key)}"

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.