Your challenge is to read a "password" from the keyboard / standard input.


  • Read a string s invisibly.
  • For each of the characters in s, print a character c.
  • In realtime.


  • You must print c in realtime. As soon as the user enters a character you must display c.
  • c must be constant, i.e. it must be the same character.
  • c can be any visible character (i.e. it cannot be a newline, space, tab, or unprintable).
  • c can't be based on s, i.e. c must be defined/constant before s is read.
  • c must be the same every time the program is run.
  • c can be one of the characters in s if by accident, as long as all other rules are followed.
  • None of the characters of s may appear on the screen, c excepted (see previous rule).
  • You may use any reasonable methods of input and output as long as all other rules are followed.
  • You may assume that the length of s is never longer than the terminal/graphical window width.
  • If using a terminal, your program should terminate after a newline or EOF is entered.


If s was password01 and c was *, the output would look something like:



The shortest submission in each language wins.

  • \$\begingroup\$ Is python with tkinter allowed for our custom input field (like the one in HTML), such that the program does not terminate when enter is pressed, but when you close the Entry's Window (X on Windows and cmd+W on mac)? \$\endgroup\$
    – Mr. Xcoder
    Jun 9, 2017 at 16:35
  • \$\begingroup\$ @Mr.Xcoder Yes, that's valid. \$\endgroup\$
    – MD XF
    Jun 9, 2017 at 16:36
  • \$\begingroup\$ Can we use Ctrl+J to represent a literal newline in the terminal? Alternatively, can we use Ctrl+Z instead of enter? \$\endgroup\$ Jun 9, 2017 at 16:43
  • \$\begingroup\$ @ConorO'Brien Clarifying how input should end in the terminal. \$\endgroup\$
    – MD XF
    Jun 9, 2017 at 16:44
  • 2
    \$\begingroup\$ What should happen if the user presses backspace? \$\endgroup\$
    – zdimension
    Jun 10, 2017 at 20:51

34 Answers 34


Python 2 (*nix only), 75 bytes

import sys,tty
while i.read(1)!='\r':print'\b*',

(Warning: messes up your stdin and doesn't fix it, so maybe run in a screen instance if you don't want to have to restart your console).

Rod has a (shorter) Python 2 answer that only works on Windows - here's a Python 2 version that works on *nix (and not Windows, I think)

  • \$\begingroup\$ Regarding the terminal messing, running reset after the script finishes solves it. \$\endgroup\$
    – manatwork
    Jul 5, 2017 at 14:40

Befunge, 18 bytes

"**"~:!#@_0`!_ #,_

Enter a null byte to stop input


><>, 10 bytes


Try It Here

Enter a null byte to end input


Aheui (esotope), 43 bytes


Try it online!

Unfortunately, I couldn't find interactive Aheui interpreter. Aheui processer made with Javascript looks like somewhat interactive, but it doesn't print till input !!!. And input !!! just terminates program.

Many Aheui implementation put -1 into stack when there are no more input, and this code checks if input is -1. If not, just print ), because its ascii code is 40, easy to make.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.