Confuse the Word spell checker!

JavaScript, 71 characters

function f(s){return "\u202E"+s.split("").reverse().join("")+"\u202C";}

Try it out on JSFiddle.

By the way, this would be a good bit shorter in CoffeeScript (53 characters)

f=(s)->"\u202E#{s.split('').reverse().join ''}\u202C"

EDIT: I just noticed that UTF-8 requirement. That's going to be tough in JavaScript. :-/


Python3 - 51

print(''.join(chr(ord(c)+0xFEE0)for c in input()))

The lazy way!

Slightly ungolfed

r=''
for c in input():
    r += chr(ord(c) - 0x20 + 0xFF00) # convert to fullwidth ASCII range
print(r)

Common Lisp, 142

I have no font named Calibri, and most of my fonts lack these symbols, but DejaVu Sans has them. I replace letters with Mathematical Alphanumeric Symbols. The spell checker does not flag any errors. Instead, it fails to detect errors, even if words have obvious typos.

Golfed:

(ignore-errors(do(c)(())(setf c(char-code (read-char)))(write-char(code-char(cond((< 64 c 91)(+ c 120159))((< 96 c 123)(+ c 120153))(t c))))))

Ungolfed:

(ignore-errors      ; Ignore when (read-char) signals end of file.
  (do (c) (())      ; Loop forever with variable c.
    (setf c (char-code (read-char)))
    (write-char
     (code-char
      (cond
         ;; Replace A to Z with U+1D5A0 to U+1D5B9.
         ((< 64 c 91) (+ c 120159))
         ;; Replace a to z with U+1D5BA to U+1D5D3.
         ((< 96 c 123) (+ c 120153))
         ;; Keep other characters.
         (t c))))))

Usage

  • clisp asconfuse.lisp <in >out
  • ecl -shell asconfuse.lisp <in >out
  • sbcl --script asconfuse.lisp <in >out

I assume that your Lisp interpreter has Unicode support and your locale is UTF-8. Do not use abcl, because it has problems outside the Basic Multilingual Plane.

Unix clones: You can run locale in a terminal. If the line for LC_CTYPE does not mention UTF-8, try export LC_CTYPE=en_US.UTF-8.

Example

I pasted some output into LibreOffice. My text has obvious spelling errors, but LibreOffice fails to detect them. It draws no red squiggles under the words, and the spell-check button only reports, "The spellcheck is complete."

LibreOffice

The text is, " ." Firefox also finds no spelling errors in this text.

Tags:

Code Golf