Emacs, 26 bytes (possibly + 10 = 36, or − 2 = 24)
The extra key that's needed in this answer is Esc. This is on the half of the keyboard that's still intact, but isn't mentioned in the question for some reason, so might or might not give a penalty to the score. (Esc and Alt are equivalent in Emacs; Alt is also on the intact half of the keyboard but isn't mentioned in the question, but has to be held rather than tapped so I can't use it as my extra key. It would save two bytes, though, because it has a shorter encoding than Esc does.)
The program itself (the commas delimit the boundaries between bytes in the on-the-wire format that Emacs uses to accept its input):
W, S, Esc, $, D, A, Ctrl-T, S, R, W, D, Esc, $, 5, Ctrl-Q, 5, f, Ctrl-X, r, Ctrl-Space, 1, Ctrl-X, r, g, 1, Ctrl-T
Encoding of this as raw bytes, to prove byte count:
00000000: 5753 1b24 4441 1453 5257 441b 2435 1135 WS.$DA.SRWD.$5.5
00000010: 6618 7200 3118 7267 3114 f.r.1.rg1.
(Note: some of the details may vary based on how Emacs is configured; this answer requires quoted-char-radix to be set to 16, and for Emacs to use the spellcheck dictionary that's default on my British English system. Both of these seem like reasonable configuration settings, but it's possible that your copy of Emacs may be configured differently. A different dictionary would likely still give a 26-byte program, but slightly different misspellings might need to be used so that the corrections we wanted can be accepted by non-bullet-ridden keys.)
Explanation
I'm not sure whether it should have any influence on the editor wars, but Emacs seems to beat vim at least in the case of this question. Emacs is pretty suited to editor golf measured in bytes, because it relies heavily on chords which take up multiple keypresses but only a single byte (thus an Emacs program is often slower to type than the equivalent Vim program, but shorter on disk). Additionally, most of the most important Emacs commands are in the bottom-left corner of the keyboard, to be close to Ctrl, very helpful with a question like this one.
"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.", so I'm assuming that we have an empty file open in Emacs and need to type the password into it. (We'd need to save the file afterwards, and probably exit Emacs, but the bytes for that aren't being counted in other people's answers so I'm not counting them here either. It's totally doable using the left hand side of the keyboard, though, Ctrl-X, Ctrl-S, Ctrl-X, Ctrl-C.)
Taking it a command (or block of similar commands) at a time:
- W, S: Enter
WS
into the document.
- Esc, $: Invoke the spellchecker.
WS
isn't a real word, but it finds lots of similar two-letter words.
- D: Using the spellchecker, correct
WS
to PS
. (When the spellchecker is invoked using Alt-$, as happened here (Esc and Alt are equivalent to Emacs), it only checks one word, so it deactivates after doing this.)
- A: insert
A
, giving PSA
.
- Ctrl-T: Swap the previous two characters, giving
PAS
.
- S, R, W, D: Type
SRWD
, giving PASSRWD
.
- Esc, $, 5: We invoke the spellchecker again, because we want to correct our misspelled
PASSRWD
into PASSWORD
. Note that we can't have it guess the word we want on our first try, like it would with PASSWRD
, because the key to accept the closest real word is 0 which we can't press. As a result, the slightly more extreme misspelling PASSRWD
is used to push the word we want into position 5, where we can accept it.
- Ctrl-Q, 5, f: Insert the character with character code U+5f, i.e.
_
. The document now reads PASSWORD_
(or will when we start typing the next command; before then, the underscore doesn't appear in case we type another hex digit).
- Ctrl-X, r, Ctrl-Space, 1: Store the current cursor position (relative to the start of the file) in register 1. For some bizarre reason, this is 1-indexed, so (having written 9 characters so far) the cursor is at position
10
.
- Ctrl-X, r, g, 1: Copy the content of register 1 into the document. It now reads
PASSWORD_10
.
- Ctrl-T: Swap the two characters before the cursor. We now have
PASSWORD_01
, like the question asks for.
If we're allowed to use Alt, we can probably encode the "invoke spellchecker" command as the single byte a4
rather than spelling it out as 1b
24
; it appears twice, so that leads to two bytes of savings. (Most modern terminals use 1b
24
as the encoding for Alt-$ to avoid clashes with UTF-8, but the a4
encoding is also encountered from time to time, sometimes available as a configuration option.)
Possible byte savings probably involve golfier misspellings to correct. PSASWRD
would be a byte shorter to type, but unfortunately, the spellchecker doesn't seem capable of gleaning PASSWORD
out of that, so PASSRWD
is the best approach I've found so far. The register-based approach to gaining 10
is also ridiculously unwieldy, but there aren't many ways of creating numbers from nowhere in Emacs, and 0
is a painful character to get hold of otherwise. (At least there were a couple of amazingly useful coincidences: the cursor just happening to end up in position 10
, which contains a 0
, right when needed; and the fact that Emacs accepts the redundant g
register operation to insert the contents of a register into the document, in addition to the more intuitive i
.)
3What happens is you do Shift-<>? – CalculatorFeline – 2016-03-04T15:20:53.817
-1: doesn't include the
;
line ending that is required for many languages, not to mention , these challenges are typically not well received in the first place... – None – 2016-09-28T20:01:05.0131@tuskiomi You having a bad day? You realize this challenge is amazingly received and 2 years old? Look at the successful answers. Go learn some more languages besides Java. I literally just solved the challenge, so it's do-able. – mbomb007 – 2016-09-28T21:46:51.320
@mbomb007 not having a bad day. I'm strongly against challenges that promote golf / esoteric languages. – None – 2016-09-28T21:58:43.053
2@tuskiomi I see a Ruby answer, a Perl answer, and multiple Python answers... – Steven H. – 2016-09-28T22:06:06.700
@StevenH. that's good. – None – 2016-09-28T22:15:23.970
@german_guy You don't have the
Enter
orReturn
keys, so there is no WS support here. – Erik the Outgolfer – 2016-09-29T14:40:09.267Can I swap those unusable characters with their ascii codes, represented with 1 to 5? – Matthew Roh – 2017-02-16T06:32:02.840
@MatthewRoh By the spec, yes. – wizzwizz4 – 2017-02-22T19:58:03.790
Uh trying to do this in JavaScript is hard, I can't seem to get to a point of getting any useful characters... – Naruyoko – 2019-10-01T00:36:48.017
The thing is English generally use keys on the right side of the keyboard to form a word... – Naruyoko – 2019-10-01T00:55:16.210
Any chance you could include the characters : = or I cant even attempt this challenge since I need to assign values :P Also, are the arrow keys still working? – Teun Pronk – 2014-06-11T10:43:51.767
@TeunPronk added Help Mode ;) – Averroes – 2014-06-11T10:51:04.200
67Can I change the layout of the keyboard to DVORAK? – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ – 2014-06-11T10:54:05.007
3@n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ No, sorry. I'm afraid that the Agency only provide you a Qwerty Keyboard :S – Averroes – 2014-06-11T10:59:14.357
Can I assume I'm running in a Python or JS console? Because I can't think of a language where I can actually print anything at all without the right side of the keyboard :s – Tal – 2014-06-11T11:02:09.537
@Tal You can assume it while you play in the spirit of the challenge. – Averroes – 2014-06-11T11:04:49.227
What's the third Shift character? (It doesn't look like a period or a hyphen, so...) – Volatility – 2014-06-11T11:06:49.113
1@Volatility · A middle dot (In my keyboard... I say in the Agency Keyboard is Shift + 3) – Averroes – 2014-06-11T11:12:31.213
9What bastardised version of the Spanish keyboard layout are you using which puts
&
on shift-5 rather than%
? – Peter Taylor – 2014-06-11T11:15:22.300Deleted my answer, will look for a better solution. So to make sure, besides the keys you named nothing else works? not even the keys that don't generate input? – Teun Pronk – 2014-06-11T11:16:58.353
2@PeterTaylor my bad! It's a
%
. Fixed. Hope not to cause any disrupt to other answers. – Averroes – 2014-06-11T11:20:25.2705no parenthesis, no square brackets, no chain brackets... well that must eliminate 99% of languages. – Eoin Campbell – 2014-06-11T11:21:22.237
1It's much more troublesome without
&
. – gxtaillon – 2014-06-11T11:50:53.53342Do we get the enter key at least? – Οurous – 2014-06-11T11:51:52.060
4Is "·" === "." ?
This will brainfuck brainfuck.... – Tejas Kale – 2014-06-11T12:08:27.793
@TejasKale I hope it is, because otherwise I actually can't think of how to do this at all. – Οurous – 2014-06-11T12:10:16.493
Thinking about it again, "·" is coming from
Shift + 3
and is not equal to "." – Tejas Kale – 2014-06-11T12:16:33.3931. is not equal to · Also, maybe we could allow multiple uses of help mode adding 10 to the code count for each new key saved. – Averroes – 2014-06-11T12:30:34.710
12Where's my CAPS LOCK? Must have been multiple bullets... – Timtech – 2014-06-11T12:36:24.863
@Averroes yes do that :D are we gonna do that? :P – Teun Pronk – 2014-06-11T12:46:40.220
@Averroes Also, can you pick any key you want for the help mode? – Teun Pronk – 2014-06-11T12:49:27.410
@TeunPronk I would like to prevent someone just picking all the letters from PASSWORD_01. – Averroes – 2014-06-11T12:52:36.343
72Whitespace, here is your big chance! – german_guy – 2014-06-11T13:08:10.393
1"You have a penalization of 10 characters for use this key." Is that 10 for each press of the key, or for each distinct character used? You might want to make that clear, since current answers are scoring it the latter way. – Geobits – 2014-06-11T13:15:40.217
What about boilerplate code created by your IDE, which included disallowed characters. Can they still be there, I don't want to copy/paste from it or anything like that, if not then this excludes languages like C# and Java doesn't it? – JMK – 2014-06-11T13:30:59.563
Wouldn't you only be able to use the keys on the broken keyboard to write the program too? – Elias – 2014-06-11T13:34:52.763
@Geobits +10 for use the Help mode. Then you can use that key as many times as you want (edited, thanks). – Averroes – 2014-06-11T13:39:59.203
1@BumblebeeMan I'm afraid that it will open the door to more changes and ambiguities in the specs. – Averroes – 2014-06-11T14:32:34.517
1@Averroes No worries, at least now I can claim that I totally could have completed the challenge otherwise...honest – JMK – 2014-06-11T14:46:30.827
1If only I had some parenthesis :( – nderscore – 2014-06-11T14:47:20.857
1hopefully, before the mission i configured my PHP installation with
asp_tags
, so i can start with<%
. * hands on *..... can't use functions nor arrays.... * run run run * – Einacio – 2014-06-11T15:14:56.603Can the Help Mode key be one from the number pad section of the keyboard? – Bradley Uffner – 2014-06-11T16:43:11.377
43Why couldn't the password have been
stewardesses
? – codebreaker – 2014-06-11T18:07:13.1834
Is the character map a virtual keyboard? http://i.imgur.com/Bk9PHv9.png
– Shane – 2014-06-11T19:10:30.9934Is this one of these weird keyboards that doesn't have an Alt key?How did my control key survive, and my spacebar, but not my alt? – Nzall – 2014-06-11T20:40:59.927
@Shane nice try but how did you get there? :P – Averroes – 2014-06-11T20:41:36.517
4@NateKerkhofs It was a JFK bullet. It hit the keyboard multiple times. – Averroes – 2014-06-11T20:42:43.933
@BradleyUffner Nope. You can get a character but not a function or something like that. You could have the number nonetheless. – Averroes – 2014-06-11T20:44:21.413
24Joke answer: I'm a spy, I switch to the backup keyboard hidden in my watch. – Nzall – 2014-06-11T20:50:33.403
@NateKerkhofs or the one in your shoe! – Averroes – 2014-06-11T20:51:58.337
11I also hope whoever needs to enter this code can touch type really well, because there's no backspace to correct mistakes. – Nzall – 2014-06-11T20:56:58.333
8Every code-golf users should look at this question for how to create an interesting background story. – justhalf – 2014-06-12T03:26:12.193
Can I use the Tab key for auto-completion in bash? – user80551 – 2014-06-12T08:07:47.223
@user80551 I would say autocompletion will go against the spririt of the game if it make your work very easy. – Averroes – 2014-06-12T08:10:24.227
Can I use vi or emacs? or would it be a loophole? :grin: – Luka Ramishvili – 2014-06-12T08:56:31.123
"This is your last mission before retiring" - well, there's no way I'm surviving the day, then. I suppose copy-pasting characters from places like other documents or desktop icon names is out of the question; is it? – user2357112 supports Monica – 2014-06-12T09:46:34.150
< and > aren't on the left part of a keyboard – kinokijuf – 2014-06-12T10:44:08.467
@kinokijuf mine yes – Averroes – 2014-06-12T10:47:28.320
@user2357112 I would say it is – Averroes – 2014-06-12T10:48:04.097
This is a bitch in PHP :( Can't use any function because of the
()
, and a lot of functions have an underscore in them. – Martijn – 2014-06-12T11:52:16.187@Martijn next challenge will be with the other side of the keyboard :P – Averroes – 2014-06-12T12:09:17.480
2“Big Overly Massive BOMB” is not a recursive acronym because the B is fixed. – kinokijuf – 2014-06-12T12:56:51.070
18@kinokijuf: It is. It's a tail recursive acronym. – justhalf – 2014-06-13T02:08:50.127
does the mouse work? – Stack Tracer – 2014-06-14T15:37:55.990
@StackTracer Nope, you haven't a mouse. – Averroes – 2014-06-15T12:21:06.320
Although the TOO_FUNNY detector catches the standard loopholes (which is a neat idea to get around those), I’d be somewhat intrigued to see which of the standard loopholes can still work here. – alexwlchan – 2014-06-17T14:03:21.787