DEV Community

Cover image for A unicode substitution cipher algorithm

A unicode substitution cipher algorithm

Victoria Drake on January 07, 2018

Full transparency: I occasionally waste time messing around on Twitter. (Gasp! Shock!) One of the ways I waste time messing around on Twitter is by...
Collapse
 
ben profile image
Ben Halpern

π”»π•’π•žπ•Ÿ π•₯𝕙𝕒π•₯ π•šπ•€ 𝕒 π•—π•¦π•Ÿ π•₯𝕠𝕠𝕝

π”Έπ•žπ•’π•«π•šπ•Ÿπ•˜ 𝕛𝕠𝕓 π•¨π•šπ•₯𝕙 𝕒𝕝𝕝 𝕠𝕗 π•₯π•™π•šπ•€ π•π•šπ•”π•œπ•ͺ

Collapse
 
dwd profile image
Dave Cridland • Edited

>>> u''.join([ c if c == ' ' else unichr(ord(c) - 0x2352 + ord('A')) for c in s ])

I can never resist these things.

The three letter words were helpful - there's limited options there, so I thought aiming for an AND or a THE would be a good crib. The fact that you've left spaces unencoded does, of course, make this much simpler.

I do get, though, that this article isn't about cryptography. :-)

Collapse
 
victoria profile image
Victoria Drake

Python3:

''.join([ c if c == ' ' else chr(ord(c) - 0x2352 + ord('A')) for c in s ])

I love this. Let's be secret code buddies.

Collapse
 
dwd profile image
Dave Cridland

β’βŽ„βŽβ΄βŒ½βŒ―β™βŽ„βŽ‚βŽƒβŒ―βŽβ΄βΌβ΄βΌβ±β΄βŽβŒ―βŽƒβΎβŒ―β΄β½β²βΎβ³β΄βŒ―βŽˆβΎβŽ„βŽβŒ―βŽ‚βΏβ°β²β΄βŽ‚βŒ―β½β΄βŽ‡βŽƒβŒ―βŽƒβΈβΌβ΄βŒ½

Collapse
 
alephnaught2tog profile image
Max Cerrina

I feel so 𝓯π“ͺ𝓷𝓬𝔂!

Collapse
 
qm3ster profile image
Mihail Malo

I like this approach in node:

big = str => {
  const out = Buffer.from(str, "ucs2"),
    len = out.length
  for (let i = 0; i < len; i += 2) {
    const ascii = out[i]
    if (ascii < 0x21 || ascii > 0x7E) continue
    out[i] = ascii - 0x20
    out[i + 1] = 0xff
  }
  return out.toString("ucs2")
}
big("Big Chungus")

Could probably do similar with TextEncoder in web.

Collapse
 
krthr profile image
Wilson Tovar

πŸ…»πŸ…ΎπŸ…ΎπŸ…ΊπŸ†‚ πŸ…°πŸ…ΌπŸ…°πŸ†‰πŸ…ΈπŸ…½πŸ…Ά

Collapse
 
vinayjn profile image
Vinay Jain

π–œπ–”π–œ π–™π–π–Žπ–˜ π–Žπ–˜ π–˜π–” π–ˆπ–”π–”π–‘

Collapse
 
cadonau profile image
Markus Cadonau

Regarding accessibility I would avoid using such character replacements on public profiles.