Crypto-js encryption and Python decryption using HKDF key

Based on the example provided here on how to establish a shared secret and derived key between JS (Crypto-JS) and Python, I can end up with the same shared secret and derived key on both ends.

However, when I try to encrypt as below, I cannot find a way to properly decrypt from Python. My understanding is that probably I am messing with the padding or salts and hashes.

    const payload = "hello"
    var iv = CryptoJS.enc.Utf8.parse("1020304050607080");

    var test = CryptoJS.AES.encrypt(
        payload,
        derived_key,
        {iv: iv, mode: CryptoJS.mode.CBC}
    ).toString();

    console.log(test)

Output “y+In4kriw0qy4lji6/x14g==”

Python (one of the attempts):

from Crypto.Cipher import AES
from Crypto.Util.Padding import pad,unpad

iv = "1020304050607080"

test_enc = "y+In4kriw0qy4lji6/x14g=="
enc = base64.b64decode(test_enc)

cipher = AES.new(derived_key, AES.MODE_CBC, iv.encode('utf-8'))

print(base64.b64decode(cipher.decrypt(enc)))

print(unpad(cipher.decrypt(enc),16))

Any guidance here would be greatly appreciated as I am stuck for quite some time.

(I have encryption working using a password, but struggling with HKDF).

Only works in Firefox

I am new to javascript, having trouble with this assignment. My professor suggested the problem was due to needing to parseInt, but even after I added the parseInt, it still isn’t working.

This displays fine in Firefox, and the “higher” and “lower” statements are displayed, but when I run it in Chrome or Edge, only the window asking for a number will render. I did look for help, but I cant see what I’m doing wrong. Most of the suggestions Ive seen online, don’t address the code directly. Is this problem specific code related or something else?

function play() {

  let guess;
  let randNum = Math.floor(1 + Math.random() * 999);
  let guessed = false;

  while (guessed == false) {
    guess = window.prompt("Enter a number from 1 to 1000");
    parseInt(guess);
    if (guess == randNum) {
      document.writeln("<li>" + "Congratulations! You guessed the correct number!</li>");
      guessed = true;
      document.writeln("</ol>");
      document.writeln("Your guess: " + guess);
      document.writeln("Actual number: " + randNum);
    } else if (guess > randNum) {
      document.writeln("<li>" + guess + " is Too High. Try Again.</li>");
      document.writeln("</ol>");
    } else if (guess < randNum) {
      document.writeln("<li>" + guess + " is Too Low. Try Again.</li>");
      document.writeln("</ol>");
    }
  }

}

window.addEventListener("load", play, false);

Adding text at the start of a p element

Let’s say I have this paragraph:

<p id="paragraph">Hello World!</p>

I want to add “Hello StackOverflow! ” at the start of the paragraph.

document.getElementById("paragraph").innerHTML += "Hello StackOverflow! "

Adding the above line didn’t work as it adds the content to the end of the paragraph, not the start.

Is there a way to do this?

Thanks!

asign acceplate input based of off a previous input

Im making a guessing games where the user can chose a difficulty mode that then changes the range of the random number generater ie( 0 to 25 0 to 50 etc)
Below is my attempt using if statements

<

easy.addEventListener('click', easyActive) // These are the difficulties
function easyActive() {
    easy.classList.add('active')
    normal.classList.remove('active')
    hard.classList.remove('active')
    master.classList.remove('active')
    const p = document.createElement('p')
    p.className = "para"
    p.innerText = 'Easy mode sets the range from 0 to 25'
    easy.append(p)
    if(p.innerText === 'Easy mode sets the range from 0 to 25') {
    random =  Math.floor(Math.random() * 26)  
    }
}

normal.addEventListener('click', normalActive)
function normalActive() {
    easy.classList.remove('active')
    normal.classList.add('active')
    hard.classList.remove('active')
    master.classList.remove('active')
    const p = document.createElement('p')
    p.className = "para"
    p.innerText = 'Normal mode sets the range from 0 to 50'
    normal.append(p)
    if(p.innerText === 'Normal mode sets the range from 0 to 50') {
        random =  Math.floor(Math.random() * 51)      
    }
}

hard.addEventListener('click', hardActive)
function hardActive() {
    easy.classList.remove('active')
    normal.classList.remove('active')
    hard.classList.add('active')
    master.classList.remove('active')
    const p = document.createElement('p')
    p.className = "para"
    p.innerText = 'Hard mode sets the range from 0 to 100'
    hard.append(p)
    if(p.innerText === 'Hard mode sets the range from 0 to 100') {
        random =  Math.floor(Math.random() * 101)      
    }
}

master.addEventListener('click', masterActive) 
function masterActive() {
    easy.classList.remove('active')
    normal.classList.remove('active')
    hard.classList.remove('active')
    master.classList.add('active')
    const p = document.createElement('p')
    p.className = "para"
    p.innerText = "Master mode sets the range from 0 to 200"
    master.append(p)
    random = Math.floor(Math.random() * 201)
}

myForm.addEventListener('submit', click)

function click(e) {
     e.preventDefault();
     const ul = document.querySelector('.guesses') // This is what i tried to do
     if(easy.className  == "active") {
         if(guess.value > 25 || guess.value < 0 || isNaN(guess.value)) {
           alert("Please Enter a Number between 0 and 25")
    }
  } else if(normal.className == "active") {
      if(guess.value > 50 || guess.value < 0 || isNaN(guess.value)) {
           alert("Please Enter a Number between 0 and 50")
    }
   } else if(hard.className == "active") {
       if(guess.value > 100 || guess.value < 0 || isNaN(guess.value)) {
           alert("Please Enter a number between 0 and 100")
    }
   } else if(master.className == "active") {
       if(guess.value > 200 || guess.value < 0 || isNaN(guess.value)) {
        alert("Please Enter a number between 0 and 200")
   }
 } else {
 
 // The rest is jsut the guessing game

. I want to make it so that when the user inputs their guess that it only accepts an input that is between the range of the difficulty chosen

click on multiple buttons which is checked by echeckboxes

I have these buttons and want to click the selected ones at one time

  
    <div class="form-group">
      <input type="checkbox" >
      <label ><button onclick="alert('a')">button1</button></label>
    </div>
    <div class="form-group">
      <input type="checkbox" >
      <label ><button onclick="alert('b')">button2</button></label>
    </div>
    <div class="form-group">
      <input type="checkbox" >
      <label ><button onclick="alert('c')">button3</button></label>
    </div>
 

<br>
<button >go</button>

I tried some jquery stuff but not made it

Javascript, trying to get date part time only

I have a date field coming from SQL as follows:

2022-06-30T00:00:00.000Z

Im trying to get the first 10 characters (date in format yyyy-mm-dd) from it, but I can’t get it to work.

First, I tried a “left” function

textPaidThru= pt.slice(0,10)

And I got

Wed Jun 29

Then I tried moment

let textPaidThru = moment(paidThru).format('YYYY-MM-DD');

But Im getting this:

2022-06-29

No matter which method I try to use, I always get the provided date minus one day.

I encounter working with dates very hard in JS. Is there a way to get the date part only as provided by SQL? This is the value Im expecting:

2022-06-30

Thanks.

TypeError: response.postData is not a function

My code below gives the error “TypeError: response.postData is not a function”.

const puppeteer = require('puppeteer-extra')
const StealthPlugin = require('puppeteer-extra-plugin-stealth')

var url = ("https://www.adidas.com.tr/yeezy/product/GY1759")

function main(){
  puppeteer.use(StealthPlugin())
  puppeteer.launch({ headless: false }).then(async browser => {
    const page = await browser.newPage()
    await page.goto(url)
    await page.mouse.click(1000, 40);
    await page.on('response', response => {
      if (response.url() === "https://www.adidas.com.tr/rhsYl92ry/P4YX/xsLtQ/uJuJSkf31r/JGkkPDcC/QGBAD/nlbSQI"){
        console.log(response.postData())
      }
    });
  })
}
main()

I want to get the request’s post data, how can I do that ?

Error = “TypeError: response.postData is not a function”

How can i access javascript data in my django template for forloop iteration

I am using js to fetch api from django rest api and after fetching api i need to use length of fetched api obj in django template how can i do that?

Or is there any other way which this problem can be solve by?

///////////////////////////////////////////js function for fetching api///////////////////////////////////

function getName() {
        fcom=document.getElementById('fcom').value;
        dep=document.getElementById('dep').value;
        console.log(fcom, dep)
        fetch(`http://localhost:8000/create-f-company-record/${fcom}/${dep}`, {
          method: 'GET', // or 'PUT'
          headers: {
            'Content-Type': 'application/json',
          },
        })
        .then(response => response.json())
        .then(data => {
          console.log(data)
          console.log(data.length)

          temdata=data.length
          
          if(data!="0"){
            document.getElementById('length').value=5
            document.getElementById('fdate').value=data.date
            document.getElementById('fcom').value=data.FCompany
            document.getElementById('dep').value=data.depostieAmount
            document.getElementById('pay').value=data.paymenetAmount
            document.getElementById('deppaydate').value=data.DepPAyDate
            document.getElementById('net').value=data.netAmount
          }
          else{
            alert('Could not find data with this id')
            window.location.reload()
          }
        })
      }

///////////////////////////////////////django template html file//////////////////////////////////////

{% for tem in temdata %}

{% endfor %}

this temdata variable is inside js function

Selenium [JavaScript] – Find elements under embedded element with Shadow DOM [ #shadow-root (user-agent) ]

I am unable to click elements of shadow dom elements [ Refer image attached ].

var propelement = await wdriver.findElement(By.xpath('//*[@id="rptLoadingFrame"]'));
var pdf_url = await propelement.getAttribute('src')
wdriver.get(pdf_url);
//var download1  = await wdriver.findElement(By.xpath('//*[@id="download"]'));
//download1.click();

await wdriver.executeScript("document.querySelector('#viewer').shadowRoot.querySelector('#toolbar').shadowRoot.querySelector('#downloads').shadowRoot.querySelector('#download').shadowRoot.querySelector('#icon').click()");

Getting below error message

“JavascriptError: javascript error: Cannot read properties of null (reading ‘shadowRoot’)”

Kindly help.

  1. PDF viewer is embedded within iframe and no DOM visible accept element inside Embed element with #Shadow Root (user-agent)

enter image description here

  1. When I access SRC mentioned in iframe got below DOM i.e. PDF viewer. I want to click “Download” button to download the PDF.

enter image description here

js error : “‘createObjectURL’ on ‘URL’: Overload resolution failed.”

I try to display an image on a php page in js, knowing that my image via an input file.
here is my code:

<script>
  function image(){
    var x = document.getElementById("image_uploads");
    var test = URL.createObjectURL(x);
    //document.getElementById("img").src = URL.createObjectURL(x);
    }
</script>

<body>
  <div class="frItem31">
    <form name="saisie" action="" method="post">
      Image 1 :<input type="file" id="image_uploads" class="image_uploads" name="image_uploads" accept="image/*"/> 
      <br>
       <img id="img" class="img">
       <br>
       <input type="button" id="calcVitesse" class="calcVitesse" value="calculer la vitesse" onclick="image()">
    </form>
  </div>
</body>

here is the error I get:

Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed.
    at image (image.php:20:32)
    at HTMLInputElement.onclick (image.php:80:125)
image @ image.php:20
onclick @ image.php:80

Could you help me please !?!

G.B.

Discord.js using interval and clearinterval

Why is my code not working? I try when someone says: spam the bot begins spamming (it does but it will not stop) How can I fix this problem?

client.on("message", msg => {
  

let interval;

if (msg.content === 'spam') { 
  // ...
  if (!interval) {
    interval = setInterval(function() {
      msg.channel.send('yo')
        .catch(console.error);
    }, 1 * 5000);
  } else {
    message.channel.send('SPAM already running');
  }
}

if (msg.content === 'stop') {
  clearInterval(interval);
  interval = 1 * 1000000;
}
});

libraries similar to photoshop’s navigator panel

I’m working on a site with a friend and we’re using a canvas and fabric.js for plotting plants in a garden, but we have lots of space and want to be able to zoom in while maintaining a panel with a full overview of the space, indicating where in the big picture we are.

The best example I can think of is photoshop’s navigator panel:
like so

haven’t been able to find anything as I don’t know what else to call it, and keywords are beginning up a lot of unrelated content.

if there aren’t any npm packages that already exist for this, how would folks recommend building it from scratch?