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!
Alternative classical explanation of the Stern-Gerlach Experiment?
Why do academics prefer Mac/Linux?
What's is the easiest way to purchase a stock and hold it
Will this series of events work to drown the Tarrasque?
How to customize the pie chart background in PowerPoint?
Why does Taylor’s series “work”?
Why would you put your input amplifier in front of your filtering for an ECG signal?
Why would company (decision makers) wait for someone to retire, rather than lay them off, when their role is no longer needed?
What do you call bracelets you wear around the legs?
Bookshelves: the intruder
Cycling to work - 30mile return
What animals or plants were used to illustrate ideas of physics?
Can the word crowd refer to just 10 people?
Failing students when it might cause them economic ruin
Is it possible to determine from only a photo of a cityscape whether it was taken close with wide angle or from a distance with zoom?
pwaS eht tirsf dna tasl setterl fo hace dorw
Is it standard to have the first week's pay indefinitely withheld?
Prints each letter of a string in different colors. C#
Why using a variable as index of a list-item does not retrieve that item with clist_item:Nn?
Why use a retrograde orbit?
Are there any symmetric cryptosystems based on computational complexity assumptions?
Can more than one instance of Bend Luck be applied to the same roll by multiple Wild Magic sorcerers?
Is my company merging branches wrong?
Save my secrets!
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
New contributor
$endgroup$
|
show 1 more comment
$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
New contributor
$endgroup$
$begingroup$
What kind of storage may we use? Anything?
$endgroup$
– Adám
5 hours ago
$begingroup$
May we limit the valid aliases to say lowercase alphabetical words?
$endgroup$
– Adám
5 hours ago
$begingroup$
Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input
$endgroup$
– Quinn
5 hours ago
$begingroup$
Updated question to specify
$endgroup$
– Quinn
4 hours ago
$begingroup$
May we use a function rather than a full program?
$endgroup$
– Arnauld
4 hours ago
|
show 1 more comment
$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
New contributor
$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
New contributor
New contributor
edited 2 hours ago
Unrelated String
2,140313
2,140313
New contributor
asked 5 hours ago
QuinnQuinn
1744
1744
New contributor
New contributor
$begingroup$
What kind of storage may we use? Anything?
$endgroup$
– Adám
5 hours ago
$begingroup$
May we limit the valid aliases to say lowercase alphabetical words?
$endgroup$
– Adám
5 hours ago
$begingroup$
Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input
$endgroup$
– Quinn
5 hours ago
$begingroup$
Updated question to specify
$endgroup$
– Quinn
4 hours ago
$begingroup$
May we use a function rather than a full program?
$endgroup$
– Arnauld
4 hours ago
|
show 1 more comment
$begingroup$
What kind of storage may we use? Anything?
$endgroup$
– Adám
5 hours ago
$begingroup$
May we limit the valid aliases to say lowercase alphabetical words?
$endgroup$
– Adám
5 hours ago
$begingroup$
Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input
$endgroup$
– Quinn
5 hours ago
$begingroup$
Updated question to specify
$endgroup$
– Quinn
4 hours ago
$begingroup$
May we use a function rather than a full program?
$endgroup$
– Arnauld
4 hours ago
$begingroup$
What kind of storage may we use? Anything?
$endgroup$
– Adám
5 hours ago
$begingroup$
What kind of storage may we use? Anything?
$endgroup$
– Adám
5 hours ago
$begingroup$
May we limit the valid aliases to say lowercase alphabetical words?
$endgroup$
– Adám
5 hours ago
$begingroup$
May we limit the valid aliases to say lowercase alphabetical words?
$endgroup$
– Adám
5 hours ago
$begingroup$
Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input
$endgroup$
– Quinn
5 hours ago
$begingroup$
Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input
$endgroup$
– Quinn
5 hours ago
$begingroup$
Updated question to specify
$endgroup$
– Quinn
4 hours ago
$begingroup$
Updated question to specify
$endgroup$
– Quinn
4 hours ago
$begingroup$
May we use a function rather than a full program?
$endgroup$
– Arnauld
4 hours ago
$begingroup$
May we use a function rather than a full program?
$endgroup$
– Arnauld
4 hours ago
|
show 1 more comment
4 Answers
4
active
oldest
votes
$begingroup$
JavaScript (ES6), 40 37 bytes
Takes input as either (alias,password,secret)
or (alias,password)
. Returns undefined when there's no secret.
f=(a,p,s)=>(x=f[a+=[,p]],f[a]=s||x,x)
Try it online!
$endgroup$
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
4 hours ago
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=;(b=@q[a])?s&&b[w]?b[w]=s:b[w]:s&&@q[a]=w=>s
Try it online!
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 36 bytesSBCS
Ambivalent anonymous lambda. Optionally takes value as left argument and takes [alias,password]
as right argument.
⍎∊'⍎n⋄'(n'←⍺')/⍨×⎕NC(n←∊'_',¨⍵)'⍺'
Try it online!
…
"dfn";
⍺
is left argument, ⍵
is right argument:
(
…)'a'
name of left argument to the right of:
'_',¨⍵
underscore concatenated to each of the alias and the password
∊
ϵnlist (flatten)
n←
assign that to n
(for name)
⎕NC
Name Classes of those (gives 2 if defined, 0 if not)
×
sign (i.e. makes 2 into 1)
…/⍨
use that Boolean mask to filter:
'⍎n⋄'(
…)
the expression to evaluate n
with a statement separator, and:
n'←⍺'
the name followed by an assignment arrow and ⍺
∊
ϵnlist (flatten)
⍎
evaluate
$endgroup$
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$
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
);
);
Quinn is a new contributor. Be nice, and check out our Code of Conduct.
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
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
JavaScript (ES6), 40 37 bytes
Takes input as either (alias,password,secret)
or (alias,password)
. Returns undefined when there's no secret.
f=(a,p,s)=>(x=f[a+=[,p]],f[a]=s||x,x)
Try it online!
$endgroup$
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
4 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 40 37 bytes
Takes input as either (alias,password,secret)
or (alias,password)
. Returns undefined when there's no secret.
f=(a,p,s)=>(x=f[a+=[,p]],f[a]=s||x,x)
Try it online!
$endgroup$
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
4 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 40 37 bytes
Takes input as either (alias,password,secret)
or (alias,password)
. Returns undefined when there's no secret.
f=(a,p,s)=>(x=f[a+=[,p]],f[a]=s||x,x)
Try it online!
$endgroup$
JavaScript (ES6), 40 37 bytes
Takes input as either (alias,password,secret)
or (alias,password)
. Returns undefined when there's no secret.
f=(a,p,s)=>(x=f[a+=[,p]],f[a]=s||x,x)
Try it online!
edited 4 hours ago
answered 4 hours ago
ArnauldArnauld
84.1k799345
84.1k799345
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
4 hours ago
add a comment |
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
4 hours ago
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
4 hours ago
$begingroup$
Took me a second to spot how you were storing things!
$endgroup$
– Shaggy
4 hours ago
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=;(b=@q[a])?s&&b[w]?b[w]=s:b[w]:s&&@q[a]=w=>s
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=;(b=@q[a])?s&&b[w]?b[w]=s:b[w]:s&&@q[a]=w=>s
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=;(b=@q[a])?s&&b[w]?b[w]=s:b[w]:s&&@q[a]=w=>s
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=;(b=@q[a])?s&&b[w]?b[w]=s:b[w]:s&&@q[a]=w=>s
Try it online!
answered 4 hours ago
Value InkValue Ink
8,085731
8,085731
add a comment |
add a comment |
$begingroup$
APL (Dyalog Unicode), 36 bytesSBCS
Ambivalent anonymous lambda. Optionally takes value as left argument and takes [alias,password]
as right argument.
⍎∊'⍎n⋄'(n'←⍺')/⍨×⎕NC(n←∊'_',¨⍵)'⍺'
Try it online!
…
"dfn";
⍺
is left argument, ⍵
is right argument:
(
…)'a'
name of left argument to the right of:
'_',¨⍵
underscore concatenated to each of the alias and the password
∊
ϵnlist (flatten)
n←
assign that to n
(for name)
⎕NC
Name Classes of those (gives 2 if defined, 0 if not)
×
sign (i.e. makes 2 into 1)
…/⍨
use that Boolean mask to filter:
'⍎n⋄'(
…)
the expression to evaluate n
with a statement separator, and:
n'←⍺'
the name followed by an assignment arrow and ⍺
∊
ϵnlist (flatten)
⍎
evaluate
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 36 bytesSBCS
Ambivalent anonymous lambda. Optionally takes value as left argument and takes [alias,password]
as right argument.
⍎∊'⍎n⋄'(n'←⍺')/⍨×⎕NC(n←∊'_',¨⍵)'⍺'
Try it online!
…
"dfn";
⍺
is left argument, ⍵
is right argument:
(
…)'a'
name of left argument to the right of:
'_',¨⍵
underscore concatenated to each of the alias and the password
∊
ϵnlist (flatten)
n←
assign that to n
(for name)
⎕NC
Name Classes of those (gives 2 if defined, 0 if not)
×
sign (i.e. makes 2 into 1)
…/⍨
use that Boolean mask to filter:
'⍎n⋄'(
…)
the expression to evaluate n
with a statement separator, and:
n'←⍺'
the name followed by an assignment arrow and ⍺
∊
ϵnlist (flatten)
⍎
evaluate
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 36 bytesSBCS
Ambivalent anonymous lambda. Optionally takes value as left argument and takes [alias,password]
as right argument.
⍎∊'⍎n⋄'(n'←⍺')/⍨×⎕NC(n←∊'_',¨⍵)'⍺'
Try it online!
…
"dfn";
⍺
is left argument, ⍵
is right argument:
(
…)'a'
name of left argument to the right of:
'_',¨⍵
underscore concatenated to each of the alias and the password
∊
ϵnlist (flatten)
n←
assign that to n
(for name)
⎕NC
Name Classes of those (gives 2 if defined, 0 if not)
×
sign (i.e. makes 2 into 1)
…/⍨
use that Boolean mask to filter:
'⍎n⋄'(
…)
the expression to evaluate n
with a statement separator, and:
n'←⍺'
the name followed by an assignment arrow and ⍺
∊
ϵnlist (flatten)
⍎
evaluate
$endgroup$
APL (Dyalog Unicode), 36 bytesSBCS
Ambivalent anonymous lambda. Optionally takes value as left argument and takes [alias,password]
as right argument.
⍎∊'⍎n⋄'(n'←⍺')/⍨×⎕NC(n←∊'_',¨⍵)'⍺'
Try it online!
…
"dfn";
⍺
is left argument, ⍵
is right argument:
(
…)'a'
name of left argument to the right of:
'_',¨⍵
underscore concatenated to each of the alias and the password
∊
ϵnlist (flatten)
n←
assign that to n
(for name)
⎕NC
Name Classes of those (gives 2 if defined, 0 if not)
×
sign (i.e. makes 2 into 1)
…/⍨
use that Boolean mask to filter:
'⍎n⋄'(
…)
the expression to evaluate n
with a statement separator, and:
n'←⍺'
the name followed by an assignment arrow and ⍺
∊
ϵnlist (flatten)
⍎
evaluate
edited 34 mins ago
answered 52 mins ago
AdámAdám
27.7k276207
27.7k276207
add a comment |
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$
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$
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 21 mins ago
answered 30 mins ago
Chas BrownChas Brown
5,4541523
5,4541523
add a comment |
add a comment |
Quinn is a new contributor. Be nice, and check out our Code of Conduct.
Quinn is a new contributor. Be nice, and check out our Code of Conduct.
Quinn is a new contributor. Be nice, and check out our Code of Conduct.
Quinn is a new contributor. Be nice, and check out our Code of Conduct.
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
$begingroup$
What kind of storage may we use? Anything?
$endgroup$
– Adám
5 hours ago
$begingroup$
May we limit the valid aliases to say lowercase alphabetical words?
$endgroup$
– Adám
5 hours ago
$begingroup$
Yes, use anything to store it - as for aliases I think it should accept any alphanumeric input
$endgroup$
– Quinn
5 hours ago
$begingroup$
Updated question to specify
$endgroup$
– Quinn
4 hours ago
$begingroup$
May we use a function rather than a full program?
$endgroup$
– Arnauld
4 hours ago