trevorhuang1 / csp_blog

Other
0 stars 0 forks source link

CPT Warmup Individual Review #1

Open trevorhuang1 opened 9 months ago

trevorhuang1 commented 9 months ago

Key Commits

  1. Elementary password combiner

    • This is the basic code that I originally made for password combiner. It converts the text entries to binary and then uses an AND gate to combine them on a binary level.
      
      // turns into binary using function
      var binary1 = textToBinary(password1);
      var binary2 = textToBinary(password2);
      //combines with and gate
      var combined = andGate(binary1, binary2);
      console.log(binary1);
      console.log(binary2);
      // displays
      document.getElementById("combined").innerHTML = "Combined password: " + combined;
      }

    //https://stackoverflow.com/questions/14430633/how-to-convert-text-to-binary-code-in-javascript function textToBinary(text) { var binary= ""; // for every character in the text for (var i = 0; i < text.length; i++) { // concat the binary version into the var "binary" //charCodeAt(0) retrieves the unicode character code of the character at i //.toString(2) converts unicode to binary binary += text[i].charCodeAt(0).toString(2) + " "; } return binary; } function andGate(binary1, binary2) { var result = ""; var longer = 0; // takes the longer one if (binary1.length >= binary2) { longer = binary1; } else{ longer = binary2; } for (var i = 0; i < longer.length; i++) { //if both 1 then return 1 if(binary1[i] == 1 && binary2[i] == 1) { result += "1"; } //otherwise return 0 else{ result += "0"; } } return result; }

  2. Animation This code creates an animation to show the passwords combining into one with the logic gate. One thing that I really struggled with was my lack of experience with doing so. I included the w3school link which helped me.
    
    #container {
        width: 800px;
        height: 400px;
        position: relative;
        background: #006400;
    }
    .animate {
        position: relative;
    }
    #animate1 {
        float: left;
        color: black;
    }
    #animate2 {
        float: right;
        color: black;
    }
    #box {
        width: 200px;
        height: 100px;
        position: absolute;
        background: #8B0000;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        color: black;
        text-align: center;
    }
    /* Style the button that is used to open and close the collapsible content */
    .collapsible {
        background-color: #8B0000;
    @@ -96,6 +123,16 @@ courses: { compsci: {week: 1} }
    </form>
    <h2 id="combined"></h2>

Password 1 goes here
Password 2 goes here

Logic gate goes here

Githubissues.
  • Githubissues is a development platform for aggregating issues.