MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: simple cipher

  • To: mathgroup at smc.vnet.net
  • Subject: [mg55394] Re: simple cipher
  • From: D Herring <dherring at at.uiuc.dot.edu>
  • Date: Mon, 21 Mar 2005 03:02:01 -0500 (EST)
  • References: <d1jfms$s8q$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Here's another version

s1 = {1, 0, 1, 0, 0, 1, 0, 1}
s2 = {L, r, o, w, e, v, y, e}

StringJoin[Table[If[s1[[i]] == 1, ToString[s2[[i]]], ""], {i, Length[s1]}]]


and another that does the conversions outside the loop (Note the 
x_Integer converts all integers != 1)

s1 = {1, 0, 1, 0, 0, 1, 0, 1} /. {1 -> True, x_Integer -> False}
s2 = ToString /@ {L, r, o, w, e, v, y, e}

StringJoin[Table[If[s1[[i]], s2[[i]], ""], {i, Length[s1]}]]


This is a more functional approach

s1 = {1, 0, 1, 0, 0, 1, 0, 1}
s2 = {L, r, o, w, e, v, y, e}

If[#[[1]] == 1, ToString[#[[2]]], ""] & /@ Transpose[{s1, s2}] // StringJoin


One could probably find hundreds of methods to do this.

Later,
Daniel

zak wrote:
> s1 = {1, 0, 1, 0, 0, 1, 0, 1}
> s2 = {L, r, o, w, e, v, y, e}
> 
> s1 is a kind of a sieve i want to look through to s2, so i could pick
> every letter in s2 wich correspond to every digit=1 in s1 so i could
> obtain the word "love", this is like the trivial ciphers we know in
> our childhood, i have the following approach, i hope there is other
> versions.
> 
> p = Flatten[Position[s1, 1]]
> out[]= {1, 3, 6, 8}
> 
> str = "";
> Do[str = StringJoin[str, ToString[s2[[p[[i]]]]]], {i, 1, 4}]
> str
> 
> Out[]= Love
> 
> thanks
> zak
> 


  • Prev by Date: Re: simple cipher
  • Next by Date: Re: simple cipher
  • Previous by thread: Re: simple cipher
  • Next by thread: Re: simple cipher