Save my secrets!Implement Shamir's Secret Sharing reconstructionProgram to match the requirements in “The World's Worst Passwords Requirements List”Random passwords vs Common passwordsOn the Subject of Passwords3… 2… 1… Crash off!Can you find the villain's password?The bunker of the math lecturerMake a ;# interpreterXKCD Password GeneratorCrack the bank account's password!
what's the equivalent of helper in LWC?
Is the world in Game of Thrones spherical or flat?
Can you use a concentration spell while using Mantle of Majesty?
Is there a rule that prohibits us from using 2 possessives in a row?
Are grass strips more dangerous than tarmac?
Is there a way to save this session?
If Sweden was to magically float away, at what altitude would it be visible from the southern hemisphere?
Different PCB color ( is it different material? )
Why does the UK have more political parties than the US?
What people are called "кабан" and why?
What does the behaviour of water on the skin of an aircraft in flight tell us?
Is there any Biblical Basis for 400 years of silence between Old and New Testament?
The qvolume of an integer
Why don't I have ground wiring on any of my outlets?
How to write a vulnerable moment without it seeming cliche or mushy?
Can a helicopter mask itself from Radar?
How can I grammatically understand "Wir über uns"?
Could a guilty Boris Johnson be used to cancel Brexit?
Can you keep a readied action even through incapacitation?
If a problem only occurs randomly once in every N times on average, how many tests do I have to perform to be certain that it's now fixed?
Is it possible to kill all life on Earth?
Solving symbolic equation for fraction of variables
What does War Machine's "Canopy! Canopy!" line mean in "Avengers: Endgame"?
California: "For quality assurance, this phone call is being recorded"
Save my secrets!
Implement Shamir's Secret Sharing reconstructionProgram to match the requirements in “The World's Worst Passwords Requirements List”Random passwords vs Common passwordsOn the Subject of Passwords3… 2… 1… Crash off!Can you find the villain's password?The bunker of the math lecturerMake a ;# interpreterXKCD Password GeneratorCrack the bank account's password!
$begingroup$
I have so many secrets and nowhere to keep them!
The goal is simple: write a program that lets you save a string and have it be protected by a password.
The program will take an alias, password and (optional) secret as parameters.
If this is the first time the program is called with a given alias, then it will store/remember the secret, and output whatever you want.
If the program is called with an alias that has been used before, then it will output the secret for that alias iff the password is the same as the first time the program was run with that alias.
Other cases
If its the first time being called with a certain alias and no secret is given - store nothing.
If the program is called with an alias that has been used, and the password is incorrect - return any kind of error or nothing at all.
If the program is called with an alias that has been used, the password is correct and a new secret is supplied - output the old secret and replace it with the new one so that next time only the new secret is output.
If the program is called with an alias that has been used, the password is correct and no new secret is supplied - output the old secret and make sure it doesn't get replaced.
Note: These secrets/passwords do not need to be stored securely
Also note: any alphanumeric input for aliases passwords and secrets should be accepted
Standard rules apply, good luck!
code-golf stateful
$endgroup$
|
show 6 more comments
$begingroup$
I have so many secrets and nowhere to keep them!
The goal is simple: write a program that lets you save a string and have it be protected by a password.
The program will take an alias, password and (optional) secret as parameters.
If this is the first time the program is called with a given alias, then it will store/remember the secret, and output whatever you want.
If the program is called with an alias that has been used before, then it will output the secret for that alias iff the password is the same as the first time the program was run with that alias.
Other cases
If its the first time being called with a certain alias and no secret is given - store nothing.
If the program is called with an alias that has been used, and the password is incorrect - return any kind of error or nothing at all.
If the program is called with an alias that has been used, the password is correct and a new secret is supplied - output the old secret and replace it with the new one so that next time only the new secret is output.
If the program is called with an alias that has been used, the password is correct and no new secret is supplied - output the old secret and make sure it doesn't get replaced.
Note: These secrets/passwords do not need to be stored securely
Also note: any alphanumeric input for aliases passwords and secrets should be accepted
Standard rules apply, good luck!
code-golf stateful
$endgroup$
1
$begingroup$
Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input
$endgroup$
– Quinn
May 16 at 21:05
1
$begingroup$
May we use a function rather than a full program?
$endgroup$
– Arnauld
May 16 at 21:16
1
$begingroup$
@Arnauld I'll allow it
$endgroup$
– Quinn
May 16 at 21:19
1
$begingroup$
May we assume the password and secret are not the empty string?
$endgroup$
– xnor
May 17 at 2:14
1
$begingroup$
May we output a null answer (like 0 or None) in any situation where we don't output the secret?
$endgroup$
– xnor
May 17 at 2:37
|
show 6 more comments
$begingroup$
I have so many secrets and nowhere to keep them!
The goal is simple: write a program that lets you save a string and have it be protected by a password.
The program will take an alias, password and (optional) secret as parameters.
If this is the first time the program is called with a given alias, then it will store/remember the secret, and output whatever you want.
If the program is called with an alias that has been used before, then it will output the secret for that alias iff the password is the same as the first time the program was run with that alias.
Other cases
If its the first time being called with a certain alias and no secret is given - store nothing.
If the program is called with an alias that has been used, and the password is incorrect - return any kind of error or nothing at all.
If the program is called with an alias that has been used, the password is correct and a new secret is supplied - output the old secret and replace it with the new one so that next time only the new secret is output.
If the program is called with an alias that has been used, the password is correct and no new secret is supplied - output the old secret and make sure it doesn't get replaced.
Note: These secrets/passwords do not need to be stored securely
Also note: any alphanumeric input for aliases passwords and secrets should be accepted
Standard rules apply, good luck!
code-golf stateful
$endgroup$
I have so many secrets and nowhere to keep them!
The goal is simple: write a program that lets you save a string and have it be protected by a password.
The program will take an alias, password and (optional) secret as parameters.
If this is the first time the program is called with a given alias, then it will store/remember the secret, and output whatever you want.
If the program is called with an alias that has been used before, then it will output the secret for that alias iff the password is the same as the first time the program was run with that alias.
Other cases
If its the first time being called with a certain alias and no secret is given - store nothing.
If the program is called with an alias that has been used, and the password is incorrect - return any kind of error or nothing at all.
If the program is called with an alias that has been used, the password is correct and a new secret is supplied - output the old secret and replace it with the new one so that next time only the new secret is output.
If the program is called with an alias that has been used, the password is correct and no new secret is supplied - output the old secret and make sure it doesn't get replaced.
Note: These secrets/passwords do not need to be stored securely
Also note: any alphanumeric input for aliases passwords and secrets should be accepted
Standard rules apply, good luck!
code-golf stateful
code-golf stateful
edited May 16 at 23:44
Unrelated String
2,200313
2,200313
asked May 16 at 20:54
QuinnQuinn
2246
2246
1
$begingroup$
Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input
$endgroup$
– Quinn
May 16 at 21:05
1
$begingroup$
May we use a function rather than a full program?
$endgroup$
– Arnauld
May 16 at 21:16
1
$begingroup$
@Arnauld I'll allow it
$endgroup$
– Quinn
May 16 at 21:19
1
$begingroup$
May we assume the password and secret are not the empty string?
$endgroup$
– xnor
May 17 at 2:14
1
$begingroup$
May we output a null answer (like 0 or None) in any situation where we don't output the secret?
$endgroup$
– xnor
May 17 at 2:37
|
show 6 more comments
1
$begingroup$
Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input
$endgroup$
– Quinn
May 16 at 21:05
1
$begingroup$
May we use a function rather than a full program?
$endgroup$
– Arnauld
May 16 at 21:16
1
$begingroup$
@Arnauld I'll allow it
$endgroup$
– Quinn
May 16 at 21:19
1
$begingroup$
May we assume the password and secret are not the empty string?
$endgroup$
– xnor
May 17 at 2:14
1
$begingroup$
May we output a null answer (like 0 or None) in any situation where we don't output the secret?
$endgroup$
– xnor
May 17 at 2:37
1
1
$begingroup$
Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input
$endgroup$
– Quinn
May 16 at 21:05
$begingroup$
Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input
$endgroup$
– Quinn
May 16 at 21:05
1
1
$begingroup$
May we use a function rather than a full program?
$endgroup$
– Arnauld
May 16 at 21:16
$begingroup$
May we use a function rather than a full program?
$endgroup$
– Arnauld
May 16 at 21:16
1
1
$begingroup$
@Arnauld I'll allow it
$endgroup$
– Quinn
May 16 at 21:19
$begingroup$
@Arnauld I'll allow it
$endgroup$
– Quinn
May 16 at 21:19
1
1
$begingroup$
May we assume the password and secret are not the empty string?
$endgroup$
– xnor
May 17 at 2:14
$begingroup$
May we assume the password and secret are not the empty string?
$endgroup$
– xnor
May 17 at 2:14
1
1
$begingroup$
May we output a null answer (like 0 or None) in any situation where we don't output the secret?
$endgroup$
– xnor
May 17 at 2:37
$begingroup$
May we output a null answer (like 0 or None) in any situation where we don't output the secret?
$endgroup$
– xnor
May 17 at 2:37
|
show 6 more comments
6 Answers
6
active
oldest
votes
$begingroup$
JavaScript (ES6), 60 50 bytes
Saved 10 bytes thanks to @JonasWilms!
Takes input as either (alias,password,secret)
or (alias,password)
. Returns undefined the first time a secret is stored, or false if the password is incorrect.
f=(a,p,s,[P,v]=f[a]||[p])=>p==P&&(f[a]=[P,s||v],v)
Try a 1st test case online!
Try a 2nd test case online!
How?
We define a named function $f$ whose underlying object is also used to store the passwords and the secrets.
Commented
f = ( // f = named function whose underlying object is used for storage
a, // a = alias
p, // p = password
s, // s = optional secret
[P, v] = f[a] // if f[a] is defined, retrieve the password P and the secret v
|| [p] // otherwise, copy p in P
) => //
p == P && ( // if p is not equal to P, yield false; else:
f[a] = [ // update f[a]:
P, // save the new password (or leave it unchanged)
s || v // save the new secret if it's defined, or keep the previous one
], //
v // return the previous secret
) //
$endgroup$
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
May 16 at 21:53
$begingroup$
hmm, is this correct?
$endgroup$
– ngn
May 17 at 5:35
1
$begingroup$
@ngn It's most likely incorrect indeed. Thanks for reporting this. Should be fixed now.
$endgroup$
– Arnauld
May 17 at 7:16
$begingroup$
-7 bytes through storing a [password, value] array inside of the object.
$endgroup$
– Jonas Wilms
May 20 at 20:52
$begingroup$
@JonasWilms Nicely done! I can't think of any situation wherep&&
is required. So, that's another -3 bytes.
$endgroup$
– Arnauld
May 20 at 21:42
|
show 1 more comment
$begingroup$
Python 2, 94 93 bytes
def f(a,p,s=0,d=):
q,t=d.get(a,(0,0))
if q==p:d[a]=p,s or t;return t
elif q<1<s:d[a]=p,s
Try it online!
For once, Python's weird default dict parameter works in my favor...
$endgroup$
$begingroup$
Wait, using a default argument makes it just one object instead of a new one on function call? Hmmm... This explains a lot of debugging I've had to do previously lol.
$endgroup$
– HyperNeutrino
May 23 at 1:46
add a comment |
$begingroup$
Ruby, 64 bytes
Builds a hash for aliases to a single key-pair of password => secret
. Probably could be more elegant.
->a,w,s=p@q
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 34 bytes
(c=#~g~#2;#3!=##3||(#~g~#2=#3);c)&
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 140 138 134 bytes
-2 bytes thanks to @Expired Data
a=>p=>s=>(a=P.ContainsKey(a)?P[a]:P[a]=new[]p,s,o:p==a[0]?a[1]:p,s==""?s:p==a[0]?a[1]=s:s).o;var P=new Dictionary<string,string[]>()
Try it online!
$endgroup$
1
$begingroup$
138 bytes
$endgroup$
– Expired Data
May 17 at 15:35
1
$begingroup$
@ExpiredData 134, asP
doesn't have to bedynamic
now
$endgroup$
– someone
May 17 at 15:50
$begingroup$
130 bytes using the same trick again
$endgroup$
– Expired Data
May 17 at 15:59
add a comment |
$begingroup$
Python 2, 77 bytes
def f(a,p,s=0,d=):
P,S=d.get(a,(p,0))
if p==P:
if s>0:d[a]=p,s
return S
Try it online!
Similar to Chas Brown's method.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f185688%2fsave-my-secrets%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
JavaScript (ES6), 60 50 bytes
Saved 10 bytes thanks to @JonasWilms!
Takes input as either (alias,password,secret)
or (alias,password)
. Returns undefined the first time a secret is stored, or false if the password is incorrect.
f=(a,p,s,[P,v]=f[a]||[p])=>p==P&&(f[a]=[P,s||v],v)
Try a 1st test case online!
Try a 2nd test case online!
How?
We define a named function $f$ whose underlying object is also used to store the passwords and the secrets.
Commented
f = ( // f = named function whose underlying object is used for storage
a, // a = alias
p, // p = password
s, // s = optional secret
[P, v] = f[a] // if f[a] is defined, retrieve the password P and the secret v
|| [p] // otherwise, copy p in P
) => //
p == P && ( // if p is not equal to P, yield false; else:
f[a] = [ // update f[a]:
P, // save the new password (or leave it unchanged)
s || v // save the new secret if it's defined, or keep the previous one
], //
v // return the previous secret
) //
$endgroup$
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
May 16 at 21:53
$begingroup$
hmm, is this correct?
$endgroup$
– ngn
May 17 at 5:35
1
$begingroup$
@ngn It's most likely incorrect indeed. Thanks for reporting this. Should be fixed now.
$endgroup$
– Arnauld
May 17 at 7:16
$begingroup$
-7 bytes through storing a [password, value] array inside of the object.
$endgroup$
– Jonas Wilms
May 20 at 20:52
$begingroup$
@JonasWilms Nicely done! I can't think of any situation wherep&&
is required. So, that's another -3 bytes.
$endgroup$
– Arnauld
May 20 at 21:42
|
show 1 more comment
$begingroup$
JavaScript (ES6), 60 50 bytes
Saved 10 bytes thanks to @JonasWilms!
Takes input as either (alias,password,secret)
or (alias,password)
. Returns undefined the first time a secret is stored, or false if the password is incorrect.
f=(a,p,s,[P,v]=f[a]||[p])=>p==P&&(f[a]=[P,s||v],v)
Try a 1st test case online!
Try a 2nd test case online!
How?
We define a named function $f$ whose underlying object is also used to store the passwords and the secrets.
Commented
f = ( // f = named function whose underlying object is used for storage
a, // a = alias
p, // p = password
s, // s = optional secret
[P, v] = f[a] // if f[a] is defined, retrieve the password P and the secret v
|| [p] // otherwise, copy p in P
) => //
p == P && ( // if p is not equal to P, yield false; else:
f[a] = [ // update f[a]:
P, // save the new password (or leave it unchanged)
s || v // save the new secret if it's defined, or keep the previous one
], //
v // return the previous secret
) //
$endgroup$
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
May 16 at 21:53
$begingroup$
hmm, is this correct?
$endgroup$
– ngn
May 17 at 5:35
1
$begingroup$
@ngn It's most likely incorrect indeed. Thanks for reporting this. Should be fixed now.
$endgroup$
– Arnauld
May 17 at 7:16
$begingroup$
-7 bytes through storing a [password, value] array inside of the object.
$endgroup$
– Jonas Wilms
May 20 at 20:52
$begingroup$
@JonasWilms Nicely done! I can't think of any situation wherep&&
is required. So, that's another -3 bytes.
$endgroup$
– Arnauld
May 20 at 21:42
|
show 1 more comment
$begingroup$
JavaScript (ES6), 60 50 bytes
Saved 10 bytes thanks to @JonasWilms!
Takes input as either (alias,password,secret)
or (alias,password)
. Returns undefined the first time a secret is stored, or false if the password is incorrect.
f=(a,p,s,[P,v]=f[a]||[p])=>p==P&&(f[a]=[P,s||v],v)
Try a 1st test case online!
Try a 2nd test case online!
How?
We define a named function $f$ whose underlying object is also used to store the passwords and the secrets.
Commented
f = ( // f = named function whose underlying object is used for storage
a, // a = alias
p, // p = password
s, // s = optional secret
[P, v] = f[a] // if f[a] is defined, retrieve the password P and the secret v
|| [p] // otherwise, copy p in P
) => //
p == P && ( // if p is not equal to P, yield false; else:
f[a] = [ // update f[a]:
P, // save the new password (or leave it unchanged)
s || v // save the new secret if it's defined, or keep the previous one
], //
v // return the previous secret
) //
$endgroup$
JavaScript (ES6), 60 50 bytes
Saved 10 bytes thanks to @JonasWilms!
Takes input as either (alias,password,secret)
or (alias,password)
. Returns undefined the first time a secret is stored, or false if the password is incorrect.
f=(a,p,s,[P,v]=f[a]||[p])=>p==P&&(f[a]=[P,s||v],v)
Try a 1st test case online!
Try a 2nd test case online!
How?
We define a named function $f$ whose underlying object is also used to store the passwords and the secrets.
Commented
f = ( // f = named function whose underlying object is used for storage
a, // a = alias
p, // p = password
s, // s = optional secret
[P, v] = f[a] // if f[a] is defined, retrieve the password P and the secret v
|| [p] // otherwise, copy p in P
) => //
p == P && ( // if p is not equal to P, yield false; else:
f[a] = [ // update f[a]:
P, // save the new password (or leave it unchanged)
s || v // save the new secret if it's defined, or keep the previous one
], //
v // return the previous secret
) //
edited May 20 at 21:40
answered May 16 at 21:23
ArnauldArnauld
85.1k7100349
85.1k7100349
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
May 16 at 21:53
$begingroup$
hmm, is this correct?
$endgroup$
– ngn
May 17 at 5:35
1
$begingroup$
@ngn It's most likely incorrect indeed. Thanks for reporting this. Should be fixed now.
$endgroup$
– Arnauld
May 17 at 7:16
$begingroup$
-7 bytes through storing a [password, value] array inside of the object.
$endgroup$
– Jonas Wilms
May 20 at 20:52
$begingroup$
@JonasWilms Nicely done! I can't think of any situation wherep&&
is required. So, that's another -3 bytes.
$endgroup$
– Arnauld
May 20 at 21:42
|
show 1 more comment
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
May 16 at 21:53
$begingroup$
hmm, is this correct?
$endgroup$
– ngn
May 17 at 5:35
1
$begingroup$
@ngn It's most likely incorrect indeed. Thanks for reporting this. Should be fixed now.
$endgroup$
– Arnauld
May 17 at 7:16
$begingroup$
-7 bytes through storing a [password, value] array inside of the object.
$endgroup$
– Jonas Wilms
May 20 at 20:52
$begingroup$
@JonasWilms Nicely done! I can't think of any situation wherep&&
is required. So, that's another -3 bytes.
$endgroup$
– Arnauld
May 20 at 21:42
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
May 16 at 21:53
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
May 16 at 21:53
$begingroup$
hmm, is this correct?
$endgroup$
– ngn
May 17 at 5:35
$begingroup$
hmm, is this correct?
$endgroup$
– ngn
May 17 at 5:35
1
1
$begingroup$
@ngn It's most likely incorrect indeed. Thanks for reporting this. Should be fixed now.
$endgroup$
– Arnauld
May 17 at 7:16
$begingroup$
@ngn It's most likely incorrect indeed. Thanks for reporting this. Should be fixed now.
$endgroup$
– Arnauld
May 17 at 7:16
$begingroup$
-7 bytes through storing a [password, value] array inside of the object.
$endgroup$
– Jonas Wilms
May 20 at 20:52
$begingroup$
-7 bytes through storing a [password, value] array inside of the object.
$endgroup$
– Jonas Wilms
May 20 at 20:52
$begingroup$
@JonasWilms Nicely done! I can't think of any situation where
p&&
is required. So, that's another -3 bytes.$endgroup$
– Arnauld
May 20 at 21:42
$begingroup$
@JonasWilms Nicely done! I can't think of any situation where
p&&
is required. So, that's another -3 bytes.$endgroup$
– Arnauld
May 20 at 21:42
|
show 1 more comment
$begingroup$
Python 2, 94 93 bytes
def f(a,p,s=0,d=):
q,t=d.get(a,(0,0))
if q==p:d[a]=p,s or t;return t
elif q<1<s:d[a]=p,s
Try it online!
For once, Python's weird default dict parameter works in my favor...
$endgroup$
$begingroup$
Wait, using a default argument makes it just one object instead of a new one on function call? Hmmm... This explains a lot of debugging I've had to do previously lol.
$endgroup$
– HyperNeutrino
May 23 at 1:46
add a comment |
$begingroup$
Python 2, 94 93 bytes
def f(a,p,s=0,d=):
q,t=d.get(a,(0,0))
if q==p:d[a]=p,s or t;return t
elif q<1<s:d[a]=p,s
Try it online!
For once, Python's weird default dict parameter works in my favor...
$endgroup$
$begingroup$
Wait, using a default argument makes it just one object instead of a new one on function call? Hmmm... This explains a lot of debugging I've had to do previously lol.
$endgroup$
– HyperNeutrino
May 23 at 1:46
add a comment |
$begingroup$
Python 2, 94 93 bytes
def f(a,p,s=0,d=):
q,t=d.get(a,(0,0))
if q==p:d[a]=p,s or t;return t
elif q<1<s:d[a]=p,s
Try it online!
For once, Python's weird default dict parameter works in my favor...
$endgroup$
Python 2, 94 93 bytes
def f(a,p,s=0,d=):
q,t=d.get(a,(0,0))
if q==p:d[a]=p,s or t;return t
elif q<1<s:d[a]=p,s
Try it online!
For once, Python's weird default dict parameter works in my favor...
edited May 17 at 1:44
answered May 17 at 1:35
Chas BrownChas Brown
5,5491623
5,5491623
$begingroup$
Wait, using a default argument makes it just one object instead of a new one on function call? Hmmm... This explains a lot of debugging I've had to do previously lol.
$endgroup$
– HyperNeutrino
May 23 at 1:46
add a comment |
$begingroup$
Wait, using a default argument makes it just one object instead of a new one on function call? Hmmm... This explains a lot of debugging I've had to do previously lol.
$endgroup$
– HyperNeutrino
May 23 at 1:46
$begingroup$
Wait, using a default argument makes it just one object instead of a new one on function call? Hmmm... This explains a lot of debugging I've had to do previously lol.
$endgroup$
– HyperNeutrino
May 23 at 1:46
$begingroup$
Wait, using a default argument makes it just one object instead of a new one on function call? Hmmm... This explains a lot of debugging I've had to do previously lol.
$endgroup$
– HyperNeutrino
May 23 at 1:46
add a comment |
$begingroup$
Ruby, 64 bytes
Builds a hash for aliases to a single key-pair of password => secret
. Probably could be more elegant.
->a,w,s=p@q
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 64 bytes
Builds a hash for aliases to a single key-pair of password => secret
. Probably could be more elegant.
->a,w,s=p@q
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 64 bytes
Builds a hash for aliases to a single key-pair of password => secret
. Probably could be more elegant.
->a,w,s=p@q
Try it online!
$endgroup$
Ruby, 64 bytes
Builds a hash for aliases to a single key-pair of password => secret
. Probably could be more elegant.
->a,w,s=p@q
Try it online!
answered May 16 at 21:42
Value InkValue Ink
8,205731
8,205731
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 34 bytes
(c=#~g~#2;#3!=##3||(#~g~#2=#3);c)&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 34 bytes
(c=#~g~#2;#3!=##3||(#~g~#2=#3);c)&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 34 bytes
(c=#~g~#2;#3!=##3||(#~g~#2=#3);c)&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 34 bytes
(c=#~g~#2;#3!=##3||(#~g~#2=#3);c)&
Try it online!
answered May 17 at 7:04
attinatattinat
1,05717
1,05717
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 140 138 134 bytes
-2 bytes thanks to @Expired Data
a=>p=>s=>(a=P.ContainsKey(a)?P[a]:P[a]=new[]p,s,o:p==a[0]?a[1]:p,s==""?s:p==a[0]?a[1]=s:s).o;var P=new Dictionary<string,string[]>()
Try it online!
$endgroup$
1
$begingroup$
138 bytes
$endgroup$
– Expired Data
May 17 at 15:35
1
$begingroup$
@ExpiredData 134, asP
doesn't have to bedynamic
now
$endgroup$
– someone
May 17 at 15:50
$begingroup$
130 bytes using the same trick again
$endgroup$
– Expired Data
May 17 at 15:59
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 140 138 134 bytes
-2 bytes thanks to @Expired Data
a=>p=>s=>(a=P.ContainsKey(a)?P[a]:P[a]=new[]p,s,o:p==a[0]?a[1]:p,s==""?s:p==a[0]?a[1]=s:s).o;var P=new Dictionary<string,string[]>()
Try it online!
$endgroup$
1
$begingroup$
138 bytes
$endgroup$
– Expired Data
May 17 at 15:35
1
$begingroup$
@ExpiredData 134, asP
doesn't have to bedynamic
now
$endgroup$
– someone
May 17 at 15:50
$begingroup$
130 bytes using the same trick again
$endgroup$
– Expired Data
May 17 at 15:59
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 140 138 134 bytes
-2 bytes thanks to @Expired Data
a=>p=>s=>(a=P.ContainsKey(a)?P[a]:P[a]=new[]p,s,o:p==a[0]?a[1]:p,s==""?s:p==a[0]?a[1]=s:s).o;var P=new Dictionary<string,string[]>()
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 140 138 134 bytes
-2 bytes thanks to @Expired Data
a=>p=>s=>(a=P.ContainsKey(a)?P[a]:P[a]=new[]p,s,o:p==a[0]?a[1]:p,s==""?s:p==a[0]?a[1]=s:s).o;var P=new Dictionary<string,string[]>()
Try it online!
edited May 17 at 15:46
answered May 17 at 15:31
someonesomeone
9091023
9091023
1
$begingroup$
138 bytes
$endgroup$
– Expired Data
May 17 at 15:35
1
$begingroup$
@ExpiredData 134, asP
doesn't have to bedynamic
now
$endgroup$
– someone
May 17 at 15:50
$begingroup$
130 bytes using the same trick again
$endgroup$
– Expired Data
May 17 at 15:59
add a comment |
1
$begingroup$
138 bytes
$endgroup$
– Expired Data
May 17 at 15:35
1
$begingroup$
@ExpiredData 134, asP
doesn't have to bedynamic
now
$endgroup$
– someone
May 17 at 15:50
$begingroup$
130 bytes using the same trick again
$endgroup$
– Expired Data
May 17 at 15:59
1
1
$begingroup$
138 bytes
$endgroup$
– Expired Data
May 17 at 15:35
$begingroup$
138 bytes
$endgroup$
– Expired Data
May 17 at 15:35
1
1
$begingroup$
@ExpiredData 134, as
P
doesn't have to be dynamic
now$endgroup$
– someone
May 17 at 15:50
$begingroup$
@ExpiredData 134, as
P
doesn't have to be dynamic
now$endgroup$
– someone
May 17 at 15:50
$begingroup$
130 bytes using the same trick again
$endgroup$
– Expired Data
May 17 at 15:59
$begingroup$
130 bytes using the same trick again
$endgroup$
– Expired Data
May 17 at 15:59
add a comment |
$begingroup$
Python 2, 77 bytes
def f(a,p,s=0,d=):
P,S=d.get(a,(p,0))
if p==P:
if s>0:d[a]=p,s
return S
Try it online!
Similar to Chas Brown's method.
$endgroup$
add a comment |
$begingroup$
Python 2, 77 bytes
def f(a,p,s=0,d=):
P,S=d.get(a,(p,0))
if p==P:
if s>0:d[a]=p,s
return S
Try it online!
Similar to Chas Brown's method.
$endgroup$
add a comment |
$begingroup$
Python 2, 77 bytes
def f(a,p,s=0,d=):
P,S=d.get(a,(p,0))
if p==P:
if s>0:d[a]=p,s
return S
Try it online!
Similar to Chas Brown's method.
$endgroup$
Python 2, 77 bytes
def f(a,p,s=0,d=):
P,S=d.get(a,(p,0))
if p==P:
if s>0:d[a]=p,s
return S
Try it online!
Similar to Chas Brown's method.
answered May 22 at 0:19
xnorxnor
95.9k18197458
95.9k18197458
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f185688%2fsave-my-secrets%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$begingroup$
Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input
$endgroup$
– Quinn
May 16 at 21:05
1
$begingroup$
May we use a function rather than a full program?
$endgroup$
– Arnauld
May 16 at 21:16
1
$begingroup$
@Arnauld I'll allow it
$endgroup$
– Quinn
May 16 at 21:19
1
$begingroup$
May we assume the password and secret are not the empty string?
$endgroup$
– xnor
May 17 at 2:14
1
$begingroup$
May we output a null answer (like 0 or None) in any situation where we don't output the secret?
$endgroup$
– xnor
May 17 at 2:37