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!













14












$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!










share|improve this question











$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















14












$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!










share|improve this question











$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













14












14








14


1



$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!










share|improve this question











$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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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










6 Answers
6






active

oldest

votes


















10












$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
) //





share|improve this answer











$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 where p&& is required. So, that's another -3 bytes.
    $endgroup$
    – Arnauld
    May 20 at 21:42


















6












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






share|improve this answer











$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


















3












$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!






share|improve this answer









$endgroup$




















    2












    $begingroup$


    Wolfram Language (Mathematica), 34 bytes



    (c=#~g~#2;#3!=##3||(#~g~#2=#3);c)&


    Try it online!






    share|improve this answer









    $endgroup$




















      1












      $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!






      share|improve this answer











      $endgroup$








      • 1




        $begingroup$
        138 bytes
        $endgroup$
        – Expired Data
        May 17 at 15:35






      • 1




        $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


















      0












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






      share|improve this answer









      $endgroup$













        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
        );



        );













        draft saved

        draft discarded


















        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









        10












        $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
        ) //





        share|improve this answer











        $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 where p&& is required. So, that's another -3 bytes.
          $endgroup$
          – Arnauld
          May 20 at 21:42















        10












        $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
        ) //





        share|improve this answer











        $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 where p&& is required. So, that's another -3 bytes.
          $endgroup$
          – Arnauld
          May 20 at 21:42













        10












        10








        10





        $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
        ) //





        share|improve this answer











        $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
        ) //






        share|improve this answer














        share|improve this answer



        share|improve this answer








        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 where p&& 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$
          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 where p&& 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











        6












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






        share|improve this answer











        $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















        6












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






        share|improve this answer











        $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













        6












        6








        6





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






        share|improve this answer











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







        share|improve this answer














        share|improve this answer



        share|improve this answer








        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
















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











        3












        $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!






        share|improve this answer









        $endgroup$

















          3












          $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!






          share|improve this answer









          $endgroup$















            3












            3








            3





            $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!






            share|improve this answer









            $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!







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 16 at 21:42









            Value InkValue Ink

            8,205731




            8,205731





















                2












                $begingroup$


                Wolfram Language (Mathematica), 34 bytes



                (c=#~g~#2;#3!=##3||(#~g~#2=#3);c)&


                Try it online!






                share|improve this answer









                $endgroup$

















                  2












                  $begingroup$


                  Wolfram Language (Mathematica), 34 bytes



                  (c=#~g~#2;#3!=##3||(#~g~#2=#3);c)&


                  Try it online!






                  share|improve this answer









                  $endgroup$















                    2












                    2








                    2





                    $begingroup$


                    Wolfram Language (Mathematica), 34 bytes



                    (c=#~g~#2;#3!=##3||(#~g~#2=#3);c)&


                    Try it online!






                    share|improve this answer









                    $endgroup$




                    Wolfram Language (Mathematica), 34 bytes



                    (c=#~g~#2;#3!=##3||(#~g~#2=#3);c)&


                    Try it online!







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered May 17 at 7:04









                    attinatattinat

                    1,05717




                    1,05717





















                        1












                        $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!






                        share|improve this answer











                        $endgroup$








                        • 1




                          $begingroup$
                          138 bytes
                          $endgroup$
                          – Expired Data
                          May 17 at 15:35






                        • 1




                          $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















                        1












                        $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!






                        share|improve this answer











                        $endgroup$








                        • 1




                          $begingroup$
                          138 bytes
                          $endgroup$
                          – Expired Data
                          May 17 at 15:35






                        • 1




                          $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













                        1












                        1








                        1





                        $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!






                        share|improve this answer











                        $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!







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        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, 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












                        • 1




                          $begingroup$
                          138 bytes
                          $endgroup$
                          – Expired Data
                          May 17 at 15:35






                        • 1




                          $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







                        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











                        0












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






                        share|improve this answer









                        $endgroup$

















                          0












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






                          share|improve this answer









                          $endgroup$















                            0












                            0








                            0





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






                            share|improve this answer









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







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered May 22 at 0:19









                            xnorxnor

                            95.9k18197458




                            95.9k18197458



























                                draft saved

                                draft discarded
















































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




                                draft saved


                                draft discarded














                                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





















































                                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







                                Popular posts from this blog

                                Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

                                Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

                                What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company