Read a password

20

4

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

Challenge:

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

Rules:

  • 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.

Example:

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

password

Winner:

The shortest submission in each language wins.

MD XF

Posted 2017-06-09T16:20:56.953

Reputation: 11 605

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)? – Mr. Xcoder – 2017-06-09T16:35:56.017

@Mr.Xcoder Yes, that's valid. – MD XF – 2017-06-09T16:36:26.110

Can we use Ctrl+J to represent a literal newline in the terminal? Alternatively, can we use Ctrl+Z instead of enter? – Conor O'Brien – 2017-06-09T16:43:54.757

@ConorO'Brien Clarifying how input should end in the terminal. – MD XF – 2017-06-09T16:44:20.247

You cannot enter EOF, as EOF isn't a character. Should our program finish when EOF is encountered (i.e., when the input stream ends), or when the user presses a certain key combo? – Dennis – 2017-06-10T19:33:43.750

Also, your own answer finishes when Ctrl-C is pressed. Is that allowed? – Dennis – 2017-06-10T19:54:32.847

2What should happen if the user presses backspace? – zdimension – 2017-06-10T20:51:04.073

Aren't rules 4, 5, 6, and 7 covered by rule 2? – Esolanging Fruit – 2017-06-13T08:14:09.797

what characters can typed? special characters !?/$, Alt Shift Ctrl etc.? – phil294 – 2017-06-13T11:49:57.100

Answers

6

str, 5 bytes

n=?,1

Due to a bug, this is 5 bytes. It should be only 1 byte:

1

Execution of <code>n=?,1</code>

Conor O'Brien

Posted 2017-06-09T16:20:56.953

Reputation: 36 228

Definitely saw the cmder answer coming due to your Ctrl+Z comment :P – MD XF – 2017-06-09T16:53:30.143

10/10 right tool for the job – Erik the Outgolfer – 2017-06-09T17:16:27.447

20

HTML, 20 bytes

<input type=password


Alternative: HTML + JavaScript, 51 bytes

Although the OP has confirmed that to be valid, here's a solution using JS for the purists!

<input id=i oninput=i.value=i.value.replace(/./g,8)

Shaggy

Posted 2017-06-09T16:20:56.953

Reputation: 24 623

4FGITW, anyone? :P (took him literally ten seconds) – MD XF – 2017-06-09T16:21:40.377

oninput=_=>i.value=i.value.replace(/./g,"*") saves a byte. – Arjun – 2017-06-09T16:54:52.087

Since c can be anything, you can save two more bytes with oninput=_=>i.value=i.value.replace(/./g,1) – Arjun – 2017-06-09T17:01:00.160

I'll worry about that if (when) someone declares my HTML-only solution invalid, @Arjun ;) I only threw the JS one together quickly to placate a few people! – Shaggy – 2017-06-09T17:07:51.407

6Where's the explanation, I don't understand. – Magic Octopus Urn – 2017-06-09T17:27:44.803

@Downvoter, a comment would be appreciated. – Shaggy – 2017-06-09T18:19:35.673

Thanks for the accept, @MDXF but there are plenty of solutions shorter than this. – Shaggy – 2017-07-23T12:29:28.030

@Shaggy The shortest submission *in each language* wins. This is the shortest HTML answer, so I can, by the rules, accept it. – MD XF – 2017-07-23T15:27:32.163

11

Vim, 36 bytes:

:im <C-v><CR> <C-v><esc>ZQ<CR>:au I<tab><tab> * let v:char=0<CR>i

This uses vim-key notation, so <C-v> is control-v, <CR> is enter, <esc> is the escape key, and <tab> is the tab key.

c is '0'.

Here is a hexdump to prove the byte count is accurate:

00000000: 3a69 6d20 160a 2016 1b5a 510a 3a61 7520  :im .. ..ZQ.:au 
00000010: 4909 0920 2a20 6c65 7420 763a 6368 6172  I.. * let v:char
00000020: 3d30 0a69                                =0.i

This works by running the following two ex commands:

:imap <CR> <esc>ZQ
:autocmd InsertCharPre * let v:char=0

The first one means

:imap               " Anytime the following is pressed in insert mode:
      <CR>          "   (the 'enter' key)
           <esc>ZQ  " Then act as if the user instead pressed '<esc>ZQ' (close the buffer)

And the second one means

:autocmd                                " Automatically as vim runs:
         InsertCharPre                  "   Any time the user is about to insert a char
                       *                "   In any type of file
                         let v:char=0   "     Then instead insert a '0' character

James

Posted 2017-06-09T16:20:56.953

Reputation: 54 537

I think there's not a way for me to get down to this using my current method without ignoring spaces at the very least.. Nice answer! – nmjcman101 – 2017-06-09T17:48:43.113

o_O That's neat... – Mr. Xcoder – 2017-06-09T18:13:00.277

9

Ruby with Shoes, 29 characters

Shoes.app{edit_line secret:1}

Sample output:

password input in Ruby with Shoes

manatwork

Posted 2017-06-09T16:20:56.953

Reputation: 17 865

25Ruby with Shoes? Rails weren't enough? – Magic Octopus Urn – 2017-06-09T17:52:05.557

6

Aceto, 8 7 6 bytes

,!`XpO

Explanation:

Read a character (,), negate it (!) and conditionally exit. Print the zero on top of the stack (p) and go back to the beginning.

Run with -F to see the effect immediately (because flushing)

My first solution was based on the sandbox post, with spaces allowed as replacement characters and no need to exit on enter (4 bytes):

,'p>

L3viathan

Posted 2017-06-09T16:20:56.953

Reputation: 3 151

5

C on POSIX, 128 117 113 96 bytes

-11 thanks to Quentin searching through termios.h
-4 thanks to Quentin pointing out my stupid mistakes
-17 because Quentin is a freaking wizard.

c,t[15];f(){for(tcgetattr(1,t),t[3]&=~10,tcsetattr(1,0,t);(c=getchar())^10&&c^4;)printf(".");}

This puts STDIN into raw/invisible mode so that it can get keypresses in realtime. This takes 77 bytes and I'm sure I can golf it in a bit. Note that this does not reset STDIN upon exiting so it will mess up your terminal if you don't do so manually.

Here's how you can reset STDIN:

void stdin_reset(void)
{
    struct termios t;
    get_stdin(&t);
    t.c_lflag |= ECHO;
    t.c_lflag |= ICANON;
    set_stdin(&t);
}

Output as shown in the GIF :-)

MD XF

Posted 2017-06-09T16:20:56.953

Reputation: 11 605

1Digging into my termios.h, ECHO is 0000010 and ICANON is 0000002. This means that ~(ECHO|ICANON) is just ~10 :) – Quentin – 2017-06-09T23:39:50.600

@Quentin Edited! Cheers :D – MD XF – 2017-06-09T23:41:49.547

1Also, each != can be replaced with ^, and '\n' with 10 (assuming UTF-8) ;) – Quentin – 2017-06-09T23:47:43.733

@Quentin Oh... duh. Can't believe I missed that! – MD XF – 2017-06-09T23:54:09.293

2If we go full UB, we can replace t's storage with an array of integers. Then c_lcflags ends up at t[3], and we need neither the name or the type nor the #include, totaling 94 bytes: c,t[15];f(){for(tcgetattr(1,t),t[3]&=~10,tcsetattr(1,0,t);(c=getchar())^10&&c^4;)printf(".");} -- But maybe you'd better have me post it as an answer rather than having fun with yours :) – Quentin – 2017-06-10T00:01:58.573

1@Quentin Oh... my. You're a wizard. And I thought I was good at C... if you'd like to post it as your own answer feel free and I'll rollback my edits, otherwise I'll leave it edited into mine. – MD XF – 2017-06-10T00:47:39.633

Does f(){for(;~getch();putchar(42));} work? (I don't have a PC to test currently) – Spikatrix – 2017-06-11T10:07:55.997

@CoolGuy That only works on Windows, and as Windows is not free software, not everyone can test it and it's not allowed. – MD XF – 2017-06-11T14:02:34.797

4

x86 machine code on MS-DOS - 14 bytes

As usual, this is a full COM file, that can be run on DosBox, plus most DOS variants.

00000000  b4 08 b2 2a cd 21 80 f4  0a 3c 0d 75 f7 c3        |...*.!...<.u..|
0000000e

Commented assembly:

    org 100h

section .text

start:
    mov ah,8h       ; ah starts at 08h (read console, no echo)
    mov dl,'*'      ; write asterisks (we could have left whatever
                    ; startup value we have here, but given that dx=cs,
                    ; we have no guarantee to get a non-zero non-space
                    ; value)
lop:
    ; this loop runs twice per character read: the first time with
    ; ah = 08h (read console, no echo syscall), the second time with
    ; ah = 02h (write console); a xor is used to switch from one
    ; mode to the other
    int 21h         ; perform syscall
    xor ah,0ah      ; switch syscall 08h <=> 02h
    cmp al,0dh      ; check if we read a newline (if we wrote stuff
                    ; we are just checking the last value read, so
                    ; no harm done; at the first iteration al starts
                    ; at 0, so no risk here)
    jne lop         ; loop if it wasn't a newline
quit:
    ret             ; quit

Matteo Italia

Posted 2017-06-09T16:20:56.953

Reputation: 3 669

2...no way. That's amazing. – MD XF – 2017-06-11T14:32:01.253

Thanks, but I feel that there's still something else to trim; that xor is a woppin' 3 bytes, and would be exactly as big if I made it work on the whole ax; I tried xor ax,0a0dh / test al,al, but it's just as big because stupid test is two bytes, grrr... – Matteo Italia – 2017-06-11T14:43:56.307

3

Python 2, 50 bytes

from msvcrt import*
while'\r'!=getch():print'\b*',

Only works on windows

Rod

Posted 2017-06-09T16:20:56.953

Reputation: 17 588

1Sadly it only works on Windows :(( – Mr. Xcoder – 2017-06-09T16:50:07.227

3

Java 5-8, 125 122 131 124 bytes

class X{public static void main(String[]a){new java.awt.Frame(){{add(new javax.swing.JPasswordField());setVisible(1>0);}};}}

Ungolfed:

class X{
    public static void main(String[]a){
        new java.awt.Frame(){
            {
                add(new javax.swing.JPasswordField());
                setVisible(1>0);
            }
        };
    }
}

Result:

enter image description here

Credit:

-3 @MD XF (Pointed out my stupid mistake with String[]args)

-7 @KritixiLithos (Pointed out public class can just be class)

Magic Octopus Urn

Posted 2017-06-09T16:20:56.953

Reputation: 19 422

1Is the String[]args necessary? – MD XF – 2017-06-09T17:32:31.813

@MDXF if I wish to make the answer for Java 8 there is PLENTY of stuff I could do. However, I'm making this a generic Java answer. However, however, yes I can make that String[]a. – Magic Octopus Urn – 2017-06-09T17:34:47.737

You forgot to update the golfed answer. Also, doesn't 1>0 evaluate to 1? – MD XF – 2017-06-09T17:35:17.970

@MDXF in Java (< 8) - 1>0 evaluates to true, which is different. I'll post this same answer in Groovy. – Magic Octopus Urn – 2017-06-09T17:37:41.703

@StephenS this is a generic Java answer, not a Java 8 answer. – Magic Octopus Urn – 2017-06-09T17:42:27.507

@carusocomputing OK, mb :) – Stephen – 2017-06-09T17:44:15.220

@MDXF if you want to see the shorthand of this, see my Groovy Answer.

– Magic Octopus Urn – 2017-06-09T17:50:29.800

You can remove the public from public class X – user41805 – 2017-06-09T18:19:12.860

@KritixiLithos ah, so you can, I thought that gave errors in Java 6, apparently not... – Magic Octopus Urn – 2017-06-09T18:27:03.283

can't you replace class with interface ? With that, you can remove the public on the main method, which can save you a couple of bytes? – Alex Ferretti – 2017-07-04T13:05:59.973

@AlexFerretti That would make this answer Java 8 only, since static methods are only available on interfaces from Java 8. In that case, it'd be best to rewrite everything like this: o->new java.awt.Frame(){{add(new javax.swing.JPasswordField());setVisible(1>0);}}. – Olivier Grégoire – 2017-07-05T15:03:05.747

I didn't know that this was implemented in java 8, my bad, I learned something ^^ – Alex Ferretti – 2017-07-06T12:51:00.810

3

AHK, 17 bytes

InputBox,o,,,HIDE

Built-ins are not interesting.

Engineer Toast

Posted 2017-06-09T16:20:56.953

Reputation: 5 769

3

Mathematica 34 bytes

 InputString["",FieldMasked->True];

An single asterisk appears, after each character is keyed in. The empty quotation marks are for the title that appears in the pop-up input window.

The ; prevents the password from being printed.

enter image description here

DavidC

Posted 2017-06-09T16:20:56.953

Reputation: 24 524

Intentional leading space? – MD XF – 2018-02-09T19:49:04.430

2

Vim, 58 50 52 50 bytes

Added to make sure it handled spaces properly.

Thanks to @DJMcMayhem for a bunch of help and ideas

i:im 32 *Y94pVGg
kWcW<Space>
:im 
 ZQ
dG@"qi

In typical Vim key syntax below. The characters marked like with a ^ are Ctrl+<char>, so ^Q=Ctrl+q

i:im ^V^V32 *^[Y94pVGg^A
kWcW<Space>^[
:im ^V
 ZQ
dG@"qi

There's no TIO link, because you'd need to directly input to Vim (as opposed to pre-inputting like normal). To run the code you need to type it into Vim, and then you can type your password and hit enter. It won't do anything with the password. It won't even know what it was. As soon as you hit enter the Vim window will :q!

This works by mapping all printable ASCII to * in insert mode, and mapping <CR> to <ESC>:q!<CR>

nmjcman101

Posted 2017-06-09T16:20:56.953

Reputation: 3 274

Maybe clarify what the symbols are? I think they're supposed to be <C-v>, <esc> and <C-a> but it's hard to tell. – James – 2017-06-09T17:04:37.067

@DJMcMayhem Will do. Incidentally I think that you can paste them into Vim and they'll show up appropriately. – nmjcman101 – 2017-06-09T17:07:52.697

Some friendly competition :D – James – 2017-06-09T17:46:54.687

2

FLTK, 47 characters

Function{}{}{Fl_Window{}{}{Fl_Input{}{type 5}}}

Sample run:

bash-4.4$ fluid -c password.fl

bash-4.4$ fltk-config --compile password.cxx 
g++ -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -fvisibility-inlines-hidden -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -o 'password' 'password.cxx' -Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -lfltk -lX11

bash-4.4$ ./password 

Sample output:

password input in FLTK

manatwork

Posted 2017-06-09T16:20:56.953

Reputation: 17 865

2

Processing, 53 bytes

String a="";void draw(){text(keyPressed?a+=0:a,9,9);}

This takes input via keypresses from a graphical window. The character it chooses to represent passwords with is 0. Note that due to the high framerate, each keypress will appear as multiple 0s (and also due to the fact that this is keyPressed and not keyTyped (not a boolean) or keyrelease).

gif

user41805

Posted 2017-06-09T16:20:56.953

Reputation: 16 320

2

Bash, 54 bytes

while read -eN1 c 2>&-;[[ ${c/$'\r'/} ]];do printf X;done

For scoring purposes, $'\r' can be replaced with a literal carriage return.

Try it online! (not much to look at)

Dennis

Posted 2017-06-09T16:20:56.953

Reputation: 196 637

2

ZX81 BASIC, 54 bytes

10 IF LEN INKEY$ THEN GOTO PI
30 IF NOT LEN INKEY$ THEN GOTO EXP PI
50 IF INKEY$>"Z" THEN STOP
70 PRINT "*";
90 GOTO PI

In the ZX81 character set the printable characters are in the range space to Z, although you can't actually input a space this way as it's the break character.

ZX Spectrum BASIC, 24 bytes

10 PAUSE NOT PI: IF INKEY$>=" " THEN PRINT "*";:GOTO PI

Note that >= counts as a single-byte keyword in Sinclair BASIC (codepoint 140 in this case).

Neil

Posted 2017-06-09T16:20:56.953

Reputation: 95 035

Are the spaces between the line numbers and functions necessary? – MD XF – 2017-06-11T20:04:22.260

Could you shorten PRINT to ?, I know that works in a lot of old BASIC dialects – MD XF – 2017-06-11T20:04:37.700

@MDXF PRINT is a 1-byte token, it's just represented on screen as the 7 characters (except after THEN, when the leading space is suppressed). – Neil – 2017-06-11T21:13:58.403

2

R, 29 bytes

invisible(openssl::askpass())

Built-in that handles password entries. Opens a new window and replaces the input with dots. invisible is used to suppress printing the password to STDOUT.

JAD

Posted 2017-06-09T16:20:56.953

Reputation: 2 898

2

Tcl/Tk, 18

gri [ent .e -sh *]

Must be run on the in the interactive shell (or have abbreviations enabled):

enter image description here

sergiol

Posted 2017-06-09T16:20:56.953

Reputation: 3 055

21 bytes without the tricky command abbreviations: grid [entry .e -sh *] and -sh is an option abbreviation for -show. 23 bytes is what I'd consider a minimum for a maintainable ungolfed program doing this. – Donal Fellows – 2017-06-13T21:48:57.133

2

Vim, 15 keystrokes

:cal inp<S-tab>'')|q<cr>

<S-tab> means shift + tab.

Apparently, there is a builtin for this that I wasn't aware of. Since I really like my manual answer, and this approach is radically different, I figured I should post a new answer instead of editing.

This works by calling the inputsecret function, then immediately quitting after it exits.

James

Posted 2017-06-09T16:20:56.953

Reputation: 54 537

2

6502 machine code (C64), 22 21 bytes

0e 08 20 9f ff 20 e4 ff f0 f8 c9 0d f0 01 a9 60 20 d2 ff 50 ed

Usage: SYS 2062

Commented disassembly listing (ACME), you can uncomment the first three commented lines to launch with RUN once loaded:

!cpu 6502
!to "password2.prg",cbm
;* = $0801                               ; BASIC starts at #2049
;!byte $0d,$08,$dc,$07,$9e,$20,$32,$30   ; BASIC to load $c000
;!byte $36,$32,$00,$00,$00               ; inserts BASIC line: 2012 SYS 2062

    GETIN  =  $FFE4
    SCNKEY =  $FF9F
    CHROUT =  $FFD2

* = $080e
keyScan:
    jsr SCNKEY  ; get key
    jsr GETIN   ; put key in A

    beq keyScan ; if no key pressed loop    

    cmp #13     ; check if RETURN was pressed
    beq $081b   ; if true go to operand of next instruction (#$60 = rts)

    lda #$60    ; load char $60 into accumulator
    jsr CHROUT  ; print it

    bvc keyScan ; loop

Comments:

  • I haven't found anything in the docs, but it seems that, after the GETIN call, beq branches only where no new key presses have been recorded;
  • Using #$60 as output char, that byte can be reused as "rts" instruction when RETURN is pressed.

Matteo Beniamino

Posted 2017-06-09T16:20:56.953

Reputation: 21

2

Forth (gforth), 54 bytes

: f begin key dup 4 - swap 13 - * while ." *" repeat ;

Explanation

begin      \ enters the loop
    key    \ waits for a single character as input, places ascii code of character on stack
    dup    \ duplicates the key value on the stack
    4 -    \ subtracts 4 from the key value (shorter way of checking for not equals)
    swap   \ swaps the top two stack values
    13 -   \ subtract 13 from the key value
    *      \ multiply top two stack values (shorter version of "and")
while      \ if top of stack is true, enter loop body, else exit loop
    ." *"  \ output *
repeat     \ go back to beginning of loop

reffu

Posted 2017-06-09T16:20:56.953

Reputation: 1 361

1

Python 3 + tkinter - 63 61 bytes

from tkinter import*
t=Tk();Entry(show=1).pack();t.mainloop()

Displays a 1 for every character, ends when closing window (OP said it's allowed).

Gif

Mr. Xcoder

Posted 2017-06-09T16:20:56.953

Reputation: 39 774

Would from tkinter import* (newline) Entry(show=1).pack();Tk().mainloop() work? – Conor O'Brien – 2017-06-09T17:01:11.930

@ConorO'Brien testing – Mr. Xcoder – 2017-06-09T17:01:40.363

@ConorO'Brien no. It produces two different tkinter windows. One with the text field, one empty. It doesn't seem right to me. – Mr. Xcoder – 2017-06-09T17:03:13.600

Do you need the show=? – Esolanging Fruit – 2017-06-11T23:14:25.323

@Challenger5 Yes, we do need the show= – Mr. Xcoder – 2017-06-12T12:19:53.027

1

Groovy, 77 73 bytes

{new java.awt.Frame(){{add(new javax.swing.JPasswordField());visible=1}}}

This is an anonymous closure, with 0 required inputs.

Ungolfed:

{
    new java.awt.Frame() {
        {
            add(new javax.swing.JPasswordField())
            visible=1
        }
    }
}

Edit 1 (-4 bytes): Component#visible can be directly accessed, read more here.

Magic Octopus Urn

Posted 2017-06-09T16:20:56.953

Reputation: 19 422

1

Micro, 35 bytes

"":i{L46c:\
i~+:i
i10c=if(,a)}a
i:\

explination:

"":i                      create new blank string 'i'
    {                          begin input loop
     L                         input a character
      46c:\                    display ascii char #46 (.) (it is popped, leaving the input char from 'L'
           i~+:i               push i, flip i and the char around, concatinate them, and store that to i
                i10c=if(,a)}a  OK, a lot happens here, if a NL is in i, the loop terminates, and the final i:\ will display the input

raddish0

Posted 2017-06-09T16:20:56.953

Reputation: 91

1That's a pretty good first attempt at a language! +1 – MD XF – 2017-06-09T17:54:21.487

1

BF, 24 bytes

++++++[->++++++<],[>.<,]

Works with bf.doleczek.pl. You can send a zero char to the program with Ctrl+Z.

Alternative solution:

BF, 1 byte

,

This is a very tongue-in-cheek solution. My terminal is 0 characters wide, so please don't enter any passwords longer than that.

Esolanging Fruit

Posted 2017-06-09T16:20:56.953

Reputation: 13 542

Whoa... not bad! – MD XF – 2017-06-11T23:01:01.017

@MDXF Are you referring to the 24 byte one or the 1 byte one? – Esolanging Fruit – 2017-06-11T23:09:42.650

Clearly the 24-byte one. I completely forgot that printing \b is a thing. :P – MD XF – 2017-06-11T23:10:36.643

@MDXF What do you mean by that? \b is unprintable anyways. – Esolanging Fruit – 2017-06-11T23:11:51.067

No I mean your solution uses \b to override the input, correct? – MD XF – 2017-06-11T23:12:10.763

@MDXF No, that interpreter just doesn't print the character you typed. It's the only online interpreter I could find with that behavior. – Esolanging Fruit – 2017-06-11T23:13:36.663

Oh. That's another way to do it, I guess. – MD XF – 2017-06-11T23:13:57.953

1

PowerShell, 12 bytes

Read-Host -a

This reads input from host and, with the -a flag treats it as a securestring/password. In the ISE it pops up a message box which has a similar behavior since the ISE doesn't allow keypress capture.

PS C:\Windows\system32> Read-Host -a
************

Chirishman

Posted 2017-06-09T16:20:56.953

Reputation: 389

1

brainfuck, 21 bytes

-[+>,[<->+[<.>[-]]]<]

Last one, I promise. No input = -1, end of input = 0

How it Works

-[  Enters the loop
  +>, Get input
     [<->+ If not end of input it create the ÿ character and check if the input is not -1
          [<.>[-]]] If there was input, print the ÿ character. 
                    <] Exit the loop if end of input

Jo King

Posted 2017-06-09T16:20:56.953

Reputation: 38 234

Your code is missing a closing bracket. And why do you make it that complicated? A simple "print a 'ÿ' for every input character" could be accomplished with a simple ,[>-.,] – Dorian – 2019-06-12T07:55:17.880

@Dorian The bracket was a mistake, but the complexity arises from having to handle both no input and end of input – Jo King – 2019-06-12T09:59:18.403

1

QBasic, 48 bytes

DO
a$=INPUT$(1)
IF ASC(a$)=13THEN END
?"*";
LOOP

INPUT$(1) reads the next character from keyboard input. (This can include things like tab, backspace, and escape, but since the OP didn't say anything about those I'll assume we don't have to worry about them.) If the character is \r (ASCII 13), terminate the program; otherwise, print * without a newline. Repeat ad infinitum.

DLosc

Posted 2017-06-09T16:20:56.953

Reputation: 21 213

1

Perl + Bash, 30 bytes

print"*"while$|=1+`read -sn 1`

c is *, uses read from bash, so isn't a pure Perl solution.

Dom Hastings

Posted 2017-06-09T16:20:56.953

Reputation: 16 415

0

QBIC, 44 bytes

{X=inkey$~X<>@`|~X=chr$(13)|_X\Y=Y+@*`_C?Y

Explanation

{            DO
X=inkey$     Read a char, set it to X$
             Note that INKEY$ doesn't wait for keypress, but simply sends out "" if no key was pressed.
~X<>@`|      IF X$ has a value THEN
~X=chr$(13)| IF that value is ENTER
_X           THEN END
\            ELSE
Y=Y+@*`      append a literal * to Y$
_C           Clear the screen
?Y           Display Y$ (having 1 * for each char entered)
             The IF's and the DO-loop are auto-closed at EOF{            DO

steenbergh

Posted 2017-06-09T16:20:56.953

Reputation: 7 772

0

Python 2 (*nix only), 75 bytes

import sys,tty
i=sys.stdin
tty.setraw(i)
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)

LangeHaare

Posted 2017-06-09T16:20:56.953

Reputation: 299

Regarding the terminal messing, running reset after the script finishes solves it. – manatwork – 2017-07-05T14:40:36.140

0

Befunge, 18 bytes

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

Enter a null byte to stop input

Jo King

Posted 2017-06-09T16:20:56.953

Reputation: 38 234

0

><>, 10 bytes

"i:?!;1+?o

Try It Here

Enter a null byte to end input

Jo King

Posted 2017-06-09T16:20:56.953

Reputation: 38 234

0

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.

LegenDUST

Posted 2017-06-09T16:20:56.953

Reputation: 799