Skip to content

Commit

Permalink
show most likely msg
Browse files Browse the repository at this point in the history
  • Loading branch information
VrindavanSanap committed Dec 25, 2023
1 parent 5310317 commit 8c399b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,3 @@ export function sentence_score(string){

return parseInt(chi_squared_value )
}
console.log(sentence_score(""))
16 changes: 10 additions & 6 deletions pages/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client"
import { useState } from 'react';
import { useState, useEffect} from 'react';
import Head from 'next/head'
import Image from 'next/image'
import {IBM_Plex_Mono, Inter} from 'next/font/google'
Expand All @@ -12,8 +12,14 @@ export default function Home() {
const [message, set_message] = useState("")
const [lowest_score, set_lowest_score] = useState(10000)
const [most_likely_message, set_most_likely_message] = useState("")
console.log(typeof(lowest_score))
useEffect(() => {
handle_message_change({ target: { value: "iylhrjlhzlyjpwoly"}})
}, [])


function handle_message_change(event){


set_lowest_score(100000)
set_message(event.target.value)
}
Expand All @@ -22,14 +28,12 @@ export default function Home() {
for (let i = 0; i < 26; i++) {
const encrypted = ceaser_cipher(message, i);
const score = sentence_score(encrypted); // Limit to 2 decimal places
console.log(typeof(score))
// console.log(score, lowest_score)
if (score < lowest_score) {
set_lowest_score(score);
set_most_likely_message(encrypted);
} else {
console.log(score, lowest_score)
}
}


enc_messages.push(
<p key={i}>
Expand Down

0 comments on commit 8c399b1

Please sign in to comment.