Jump to content

Recommended Posts

I can't find the answer to this on Google because i don't even know what to ask as search keywords. 

I have a chunk of data, uploaded file data, and for each byte I need to get that byte of it and find the numeric value (0 - 255) of that byte.  I can't find anything about data or file manipulation with javascript, I think I'm asking big G the wrong way.

Link to comment
https://forums.phpfreaks.com/topic/308125-getting-numeric-value-of-data/
Share on other sites

If it's Android then why are you looking for a Javascript answer? Did you mean to say Java, even though the two are completely different languages?

You have code that's reading the contents of the file, right? At some point you should (a) have a String and you can .codePointAt(index), or (b) have a char and you can cast to int.

Ok, I have an array, table by name, it contains the numbers 0 through 255 (inclusive)in a random order. I am looping through the file data one byte at a time and i need the table's index of the numeric value that byte is equal to. So I need a way to get the numeric value of a byte so I can find it in table using .indexOf 

ok.... I'm having an odd problem here...

This code fails at line 16 because pivotTable is undefined there (line 15 is test for content), but not at line 5. But passkey at line 14 is not a problem...

01 class PivotValueEncryption{
02 constructor(){
03 var pivotTable = [162,1,53,...,93,91,16];
04 var passKey = "";
05 alert(pivotTable);
06 }
07 set key(value){
08 this.passKey = value;
09 }
10 get key(){
11 return this.passKey;
12 }
13 Pivot(character){                                             

14 alert(this.passKey);                                         

15 alert(this.pivotTable);
16 var charValue = this.pivotTable.indexOf(character.charCodeAt(0));
17 for (var i = 0; i<this.passkey.length-1; i++){
18 var pivotValue = this.pivotTable.indexOf(this.passkey.charCodeAt(i));
19 charValue = charValue + (pivotValue - charValue);
20
21 }
22 return charValue
23 }
24 }
25 var pve = new PivotValueEncryption;
26 pve.key="test";
27 alert(pve.key);
28 alert(pve.Pivot("A"))

Edited by Karaethon
14 and. 15 were out of line

Ok, i accidentally fixed it....

I changed

03 var pivotTable = [162,1,53,...,93,91,16];
04 var passKey = "";

to

03 this.pivotTable = [162,1,53,...,93,91,16];
04 this.passKey = "";

if anyone knows why this worked, I'd appreciate the explanation. 

"var" variables are only available to the function. If you define them in the constructor then you can't use them in the Pivot method.

Writing "this.pivotTable=" will create a member variable on the object instance. It's the same thing as if you wrote that in PHP.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.