Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

You have been hired for your tech knowledge as a Secret Agent's sidekick to ensure that the good guy can get his job done and the world can be saved.

This is your last mission before retiring with a high paycheck and the gratitude of the whole world. But before you have to disarm the Evil Genius' Big Overly Massive BOMB (seems that the evil genius is an smart ass who likes recursive acronyms). Anyways you and your buddy are in the very core of the Evil Genius secret base, ready to disarm the BOMB that could wipe the continent out. In your previous mission you managed to get the disarm code that to your astonishment is just "PASSWORD_01". You connect your keyboard to the BOMB and when you are ready to go the Evil Genius' henchmen enter in with a barrage of bullets. Unfortunately one of these bullets impacts on your keyboard. "Finish the job while I distract those d*ckheads!" says your buddy and then begins to fire his gun. But how could you finish the job with only half a keyboard?

SPECS

  1. Write a program that outputs in any way you want the string PASSWORD_01 (uppercase).
  2. Since your keyboard has been hit by a bullet, you can only use these keys:

    1 2 3 4 5

    Q W E R T

    A S D F G

    < > Z X C

    Ctrl Shift Tab Space

    Using the Shift key, your keyboard allows you to use these characters:

    ! " · $ %

  3. You don't have any other hardware than the keyboard and the screen (a mouse for example), neither a file with the password written in your computer.

  4. You don't have an Internet connection.

  5. You can assume you have the interpreter shell / source editor opened before the bullets came in. Sadly you have not written anything in it before the keyboard was hit.

  6. You don't have a virtual keyboard. In fact the BOMB has a TOO_FUNNY detector that will make it explode if you try to use the Standard loopholes.

  7. Since your buddy is waiting for you to finish soon to scape of the Secret Base you will have to write the smallest code possible (so it's and !).

Good luck because the count down has begun!

HELP MODE: Also a KEY (only one Key you want from the keyboard, but not the Shift + Key or any other combination) has miraculously survived too. EG: You can use =, or 0 or /… This extra key cannot be any of the letters in PASSWORD_01 (so you cannot add P or R). Name that key in your answer. You have a penalization of 10 characters for use this key regardless of how many times you use the key.

share|improve this question
43  
Can I change the layout of the keyboard to DVORAK? –  n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ Jun 11 at 10:54
29  
Do we get the enter key at least? –  Ourous Jun 11 at 11:51
52  
Whitespace, here is your big chance! –  german_guy Jun 11 at 13:08
27  
Why couldn't the password have been stewardesses? –  codebreaker Jun 11 at 18:07
12  
Joke answer: I'm a spy, I switch to the backup keyboard hidden in my watch. –  Nate Kerkhofs Jun 11 at 20:50

11 Answers 11

up vote 25 down vote accepted

CJam - 24 + 10 (() = 34

"Q"c("ASSW"1$("aRD"(((T1

No additional key - 39

211 131%c"ASSW"211 132%c"RD"321 113%cT1

Try it at http://cjam.aditsu.net/

share|improve this answer
2  
Background music: youtube.com/watch?v=6iaR3WO71j4 –  aditsu Jun 11 at 13:52

bash, vim and dc (343)

I'm sitting at a bash prompt which has been configured by the Evil Genius, and of course he has VISUAL=vim in the default environment. Using the default bash binding for edit-and-execute-command (C-x C-e) bash invokes $VISUAL and will execute its buffer contents on exit (ZZ). I type in the following sequence (Note: kbd-mode are commands issued in normal mode and control sequences):

  1. C-xC-e
  2. acat<<<45C-c4C-aaa

    Now the vim buffer contains cat<<<49a. Continuing ...

  3. 45C-c3C-aaa

  4. 54C-c41C-aaa
  5. 55C-c13C-aaa

    Now the vim buffer contains cat<<<49a48a95a68a. Continuing ...

  6. 51C-c31C-aaa

  7. 55C-c24C-aaa
  8. 44C-c43C-aaa
  9. 42C-c41C-aaa
  10. 42C-c41C-aaa
  11. 54C-c11C-aaa
  12. 55C-c25C-aaa>s

    Now the vim buffer contains cat<<<49a48a95a68a82a79a87a83a83a65a80a>s

    Get out of insert mode, save and exit

  13. C-cZZ

    The s file now contains a dc script that generates the desired string on the stack, now we need to add print commands.

  14. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

    Repeat the above command 9 times.

  15. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  16. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  17. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  18. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  19. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  20. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  21. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  22. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  23. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  24. C-xC-eacat<<< f >>s

    Execute the dc script:

  25. C-xC-eadc sC-cZZ

Output:

PASSWORD_01

Contents of the s file:

49a48a95a68a82a79a87a83a83a65a80a
P
P
P
P
P
P
P
P
P
P
f
share|improve this answer
3  
I was thinking to do a vim script because of the Ctrl character; good thinking to pair it with dc! Also, excellent solution :) –  nneonneo Jun 12 at 0:28
4  
+1 This should be the winner IMO –  DigitalTrauma Jun 12 at 0:43
2  
How long did it take you to write all those <kbd></kbd> tags? –  justhalf Jun 13 at 17:13
8  
@justhalf: I wrote it in vim with <Leader>k bound like this map <Leader>k i<kbd></kbd>^[F>a, so it wasn't as bad as it looks :-). –  Thor Jun 13 at 23:25
8  
Now it's apparent that Agent Thor knows his tool thoroughly. You deserve the retirement, sir! –  justhalf Jun 14 at 1:46

Ruby, 57 + 10 (*) = 67

$*<<4*4*5<<214%135<<44%25*5<<1%1
$><<"%cASSW%cRD%c%d1"%$*

This answer uses * and % to build the ASCII values of the missing characters (and 0 as Fixnum) and pushes them into $* (ARGV). This array is then used in combination with a format string to generate the correct password, which is printed with $><< ($> is stdout).

Ruby, 62 + 10 (.) = 72, no linebreak

$>.<< "%cASSW%cRD%c%d1".% %w%%<<311%231<<214%135<<321%113<<1%1

Roughly the same principle as the above version, except that here the array is built from an empty array literal (%w%%). Some fiddling with . is needed to get the desired operator precedence.

share|improve this answer
12  
"This is your last mission before retiring with a high paycheck and the gratitude of the whole world." Congratulations, we all thank you :) –  Timtech Jun 11 at 14:01
3  
The ultimate proof that Perl is one of the biggest inspiration of Ruby. –  Pierre Arlaud Jun 11 at 14:11
11  
How did you do the linebreak? –  Cephalopod Jun 11 at 16:21
4  
@Arian The same way nneonneo runs his Python code after typing it into the REPL ... I'll add a version without linebreak. –  Ventero Jun 11 at 21:26
    
Does the evil genius have ruby installed? –  Mhmd Jun 13 at 10:24

Whitespace (148 + 10 = 158)

Enter key needs to be used here.

SS+1010000L // Push code of P
TLSS        // Output character
SS+1000001L // Push code of A
TLSS        // Output character
SS+1010011L // Push code of S
SLS         // Duplicate top stack
TLSS
TLSS
SS+1010111L // Push code of W
TLSS
SS+1001111L // Push code of O
TLSS
SS+1010010L // Push code of R
TLSS
SS+1000100L // Push code of D
TLSS
SS+1011111L // Push code of _
TLSS
SS+0L       // Push 0
TLST        // Output number
SS+1L       // Push 1
TLST        // Output number
LLL         // End program

My notation's explanation:

  • S, +, 0 are spaces.
  • T, 1 are tabs.
  • L is new line.
  • // starts comment.

Each line is a command in whitespace language.

Demo

share|improve this answer
1  
Ah man... I was just working on that :( –  Teun Pronk Jun 11 at 13:09
1  
Me too, but I gave up on this knowing someone would be faster –  german_guy Jun 11 at 13:11
    
I thought 'L' wasn't available? –  500 - Internal Server Error Jun 12 at 14:18
    
@500-InternalServerError: Actually L stands for new line character. Check the Demo for the real code. What I posted is a readable version. –  n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ Jun 12 at 15:07
    
Ah, I get it now. –  500 - Internal Server Error Jun 12 at 15:17

Python (2200 395 + 10)

exec"""exec"exec"+"%ca"%34+"%c52+53"""+"%c55+55"%44+"%c34"%44+"%c45+35"%44+"%c"%44+"""34%%cexec"%"""+"%c"%54+"""1+"%c"%34+"%%5%c+"%5"""+"%c"%55+"""+"%c"%34+"%c"""+"%c"%112+"""r%%c%%ct%%c%%cASSW"+"%c%%34+"%34+"%c%%cRD"%34+"%c%%"""+"%c"%55+""""%34+"%c+"%5"""+"%c"%55+"""+"%c%%c"%34+"%c%%"%34+"%c5+"%5"""+"%c"%55+"""+"%c"%34+"%c1%%c"+"%c%%4"%34+"%c+"%5"""+"%c"%54+"""+"%c"%34+"%c%%a"+"%c%%34"%34"""

I needed the + character (costing +10), which can be obtained from the numpad (or on certain key layouts).

Yeah, the BOMB probably went off while I was typing that.

The basic approach is to construct ever larger character sets by using exec and "%c"%(number). There are four execs nested inside each other. Gradually, my digit set progresses up from

  1. 12345
  2. 1234567 (6 = ASCII 54, 7 = ASCII 55)
  3. 123456789 (8 = ASCII 56, 9 = ASCII 57)
  4. 0x0123456789abcdef

so that in the final iteration it is possible to express any character (so that the innermost version can actually run any program at all).

Around 50% of the program is just quote characters ("%c"%34 is a double quote), because the nested nature of the exec statements demands "escaping" quote characters aggressively.

share|improve this answer
    
If you use the "+" from the numeric keypad, you are independent from the keyboard language. –  celtschk Jun 12 at 20:31
    
@celtschk: Good point! I will edit that in. –  nneonneo Jun 12 at 20:32
1  
Rather than constructing digit sets with nested execs, couldn't you get numbers using arithmetic? Ex. exec '%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c'%(112,114,51+54,55+55,1+115,32,4+35,25+5‌​5,11+54,31+52,31+52,32+55,24+55,31+51,13+55,41+54,3+45,4+45,4+35) –  Kevin Jun 17 at 12:09
    
Because you can't get both parens. (I did consider this!) –  nneonneo Jun 17 at 13:37
    
Additionally, Python doesn't have a lot of operators that bind more strongly than %. ** is one, but it tends to be fairly useless for constructing most terms. –  nneonneo Jun 17 at 13:39

Vim + PHP on Some Window Managers

65 keys in 44 strokes, with a 10-point penalty for using =.

aEACE<Alt+Tab>z=5<Alt+Tab>$xxxxaASSWRD<Alt+Tab>z=1<Alt+Tab>
$a$aA<Alt+Tab>==wxx$r1<^X>a1

A breakdown:

  • Alt+Tab appears to work like Esc with Vim, or perhaps with this terminal emulator. Thanks for teaching me something new!
  • aEACE<Alt+Tab>: Enter append mode and insert “EACE”. Exit.
  • z=5<Alt+Tab>: Perform spelling correction. Select 5, “PEACE”. Exit. (Esc seems to work as Enter here!)
  • $xxxxaASSWRD<Alt+Tab>: Go to the end of the line. Delete 4 characters and add ASSWRD, resulting in PASSWRD. Back to normal mode. (No, 4x won’t work.)
  • z=1<Alt+Tab>: PASSWORD is probably going to be the first correction for this. Select it.
  • $a$aA<Alt+Tab>: Go to the end of the line, and add a $aA. Back to normal mode.
  • ==: Format this line of PHP nicely, changing the camelCase $aA to $a_a. This also moves the cursor back to the start of the line.
  • wxx: Go forward a word; the cursor is now before $. Delete two characters – the $ and the a – to make PASSWORD_a.
  • $r1: Go to the end of the line and replace the current character (i.e. a) with 1, resulting in PASSWORD_1.
  • ^X: Decrement the integer under the cursor, resulting in PASSWORD_0.
  • a1: Finally, append 1, for PASSWORD_01!
share|improve this answer
    
I can't replicate == command, it just toggles large indentation mode in my vi setup (debian 7, v7.3.547) –  Cengiz Can Jun 19 at 14:34

Insomnia 39

This language comes up when I was looking around for a language that encodes its instructions with single ASCII character. The language actually operates on the decimal ASCII code of the character, so it is still quite flexible with half of the keyboard destroyed.

Fddx>"eCeezdC>Cef>dx"dCezeeedeCrqeeC%4s

Here is the Insomnia interpreter for testing.

share|improve this answer

Brainfuck (553) [invalid]

So here we go, coded in Brainfuck using this interpreter. I additionally used the + key, so that's 543+10 = 553 characters, still room for improvement:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++..++++.>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++.+.

EDIT: I am sorry, this answer is invalid since the '+' is made with Shift+1 on a swiss keyboard.

share|improve this answer
8  
Where did you get that +? –  Timtech Jun 11 at 12:37
2  
@Timtech The '+' is made using [shift]+[1], and i did not use '-' –  flawr Jun 11 at 12:40
2  
[Shift]+[1] = ! –  Teun Pronk Jun 11 at 12:41
2  
@TeunPronk Oh sorry, forgot that there is a difference in the special chars on swiss keyboards. –  flawr Jun 11 at 12:43
1  
@TeunPronk Yes but I already used '.' as the help mode key. –  flawr Jun 11 at 13:16

Perl, (31+10 / 41+10 / 64+10)

(^ key used, 3 ways)

exec"easswsrdcqw"^"5    <  <AF"                   # exec "PASSWORD_01"

  • Valid if running as a system command qualifies as "output."

exec"QQZSqeasswsrdcqw"^"422<Q5    <  <AF"         # exec "echo PASSWORD_01"
  • Valid if I'm allowed to use external/OS commands. (Run here)

exec"EQAXqwQqQZQxqeasswsrdcqwxqq"^q!5434QZ4S534$S5    <  <AF$SS! 
                  # exec "perl -e\"die\\\"PASSWORD_01\\\"\""
  • Valid if I can execute Perl via the system. (Run here) <-- this one uses print instead of die

The scripts use Perl's bitwise string XOR operator ^, which does an XOR on the character bits of the two strings. This lets me recreate the missing characters for PASSWORD_01, and create the characters for the system command.

I made the three variants depending on how lenient the rules are. I assume that since variants 2 and 3 actually output the words on Ideone, the solutions are valid. I removed the little story I had here since I figured no one would read it, but you can read it in the edits if you're curious!

share|improve this answer
    
eval can't replace exec since it requires 2 new keys, v and l. It also can't be used inside the exec since eval is not a system call/program, which is what exec runs. –  Allen G Jun 18 at 14:43
    
Oh, sorry. Forgot about the restriction of the question when I made the comment. –  n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ Jun 18 at 15:35

Python (162 chars + 10)

Solved it in Python, using the "=" as an extra keyboard key. There are multiple statements, though, so I am not sure whether the "Enter" key would be a violation (since theoretically I could just hit "run" on an IDE and run all of those statements at once, without using an enter key".

exec """t="q%c=%%%%s%%c" %% 44 """ % 43
exec "q=5<<4%c" % 44
exec t % "203 % 124"
exec t % "235 % 140"
exec t % "6<<3"
"%cASSW%cRD%c%c1" % q

OUTPUT: PASSWORD_01

Anyway, I'm starting to really like Python!

share|improve this answer
1  
since theoretically I could just hit "run" on an IDE and run all of those statements at once, without using an enter key Not sure what you are talking about - before you hit run, the line separator must be there. Or am I missing something? –  n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ Jun 18 at 9:09

Octave

No extra key required, HOWEVER this outputs the password as a string in the way that I like, but does not actually output the password string. Therefore I decided not to add a character count:

"·--· ·- ··· ··· ·-- --- ·-· -·· ··——·— ----- ·----"

Will only work if the evil genius likes to input passwords in morse code.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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