Karaethon Posted January 8, 2019 Share Posted January 8, 2019 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 Share on other sites More sharing options...
requinix Posted January 8, 2019 Share Posted January 8, 2019 String.prototype.charCodeAt Link to comment Share on other sites More sharing options...
Karaethon Posted January 8, 2019 Author Share Posted January 8, 2019 Doesnt that work on string data? Or will it work with the full ascii values? Btw, this is not browser based, is android app. Link to comment Share on other sites More sharing options...
requinix Posted January 8, 2019 Share Posted January 8, 2019 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. Link to comment Share on other sites More sharing options...
Karaethon Posted January 9, 2019 Author Share Posted January 9, 2019 Yes android and yes javascript, using droidscript as my ide. Uses js as the language. Im having trouble with AIDE and java, im still learning the proper way hut also want to practice using js way. Link to comment Share on other sites More sharing options...
requinix Posted January 9, 2019 Share Posted January 9, 2019 Then yes, String.charCodeAt is for strings. But that's probably what you have to work with. So unless you can tell me more so I don't have to try to guess, that's my answer. Link to comment Share on other sites More sharing options...
Karaethon Posted January 10, 2019 Author Share Posted January 10, 2019 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 Link to comment Share on other sites More sharing options...
requinix Posted January 10, 2019 Share Posted January 10, 2019 Ohhh, well then, in that case, String.prototype.charCodeAt. Link to comment Share on other sites More sharing options...
Karaethon Posted January 10, 2019 Author Share Posted January 10, 2019 Ok. Thank you for your help. Link to comment Share on other sites More sharing options...
Karaethon Posted January 11, 2019 Author Share Posted January 11, 2019 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")) Link to comment Share on other sites More sharing options...
Karaethon Posted January 11, 2019 Author Share Posted January 11, 2019 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. Link to comment Share on other sites More sharing options...
requinix Posted January 11, 2019 Share Posted January 11, 2019 "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. Link to comment Share on other sites More sharing options...
Karaethon Posted January 11, 2019 Author Share Posted January 11, 2019 Ahhhh. Okay. Havent tried casses in php yet either, good to know. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.