What encryption could this be? [closed] - asp.net-mvc

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have a string that looks like YB[Xf`lbt+glo
What is the encryption used to encrypt this string?

I somewhat disagree with all the negative comments. While more data would of course help, it is still quite possible to make educated guesses based on the length and charset in the sample string. Some ideas off the top of my hat:
The sample has the same length as a traditional DES crypt(1) hash, albeit unexpected characters. Could be a DES crypt(1) hash with some custom output character set. Not terribly likely but possible.
The sample could be base85/ascii85 encoded, which is 80 bits of raw data. This is a rather unusual size. It could theoretically be the output of a hash function with digest size 80 bits, or longer and shortened to 80 bits, or of a block cipher with block size 80 bits (e.g. REDOC). More likely perhaps is a stream cipher.
Part of the data could be a salt or IV, assuming base85 it could quite reasonably be 16 bits of IV and a ciphertext block of 64 bits.
It could be just 80 bits of random data as e.g. a session identifier.
That's about all that can be reasonably squeezed out of the sample above I think. Not much, but it's a start. We'd need other data and information to be able to judge what is more or less likely and to confirm or rule out some of the possibilities.
(edit after the solution was posted)
For those who are interested, this is how to decode the encoded string using code from the packed JS code and running it e.g. in spidermonkey or ideone.com:
function R(t) {
var f = "";
for (var d = 0; d < t.length; d++) {
f += String.fromCharCode(t.charCodeAt(d) ^ (1 + (t.length - d) % 32));
}
return f;
}
print(R("YB[Xf`lbt+glo"));
it returns:
WOWSlider.com

just google for that string, then you find that it is an encrypted javascript
here it appears:
http://pastebin.com/tTAL1ft0
next time, please give more information where you got this string

Strictly speaking this could be created from any number of methods of encryption.
If you knew the source you might be able to do some detective work based on their technology stack but with that string alone there is no way to know for sure.

Related

Starting to write a logical expression evaluator [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I want to develop a logical expression evaluator to compute applicability of certain logical expression against a particular expression. For example,
An expression could be of the form
(A AND B) NOT C
this expression should then be evaluated with another expression like
(B AND C) OR D
The result of the evaluation in the above case is FALSE as the second expression doesn't full fill the first.
The expression can be more complex also, like it can have numerical ranges R(1-100) which means the applicability of the expression is valid through the ranges, like [A-Za-z0-9] in regular expression.
So the expression can be complex like
(A AND B) OR C AND R(1-100) NOT R(80-100)
and this has to be then evaluated by an expression like
(C OR D) AND B NOT R(1-7) AND R(25-100)
There are clear rules on when an expression satisfies another expression. So, if one has to write an expression evaluator, what is the best way to go. Since, I haven't done something before, I would like to have an head start. Any relevant pointers, or similar implementations could be vast help.
You can evaluate boolean expressions fairly easily using a stack.
basically as you see "values" you push them on the stack, as you see operators you apply them. Google "boolean expression stack" will give you plenty of hits.

how to match two images and find out mistakes [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have a template of a letter and many of it's variations (see below) which i acquire from a digital pen :
Template
Test 1
Test 2
These letters are scaled to be in the same bounding box .
I want to detect the mistakes in the letter , like the mistake in Test 1 is that that there is a extra line , and mistake in Test 2 is that there is a missing segment . Similarly there can be a mistake in which there is a curve instead of a line segment . I want to find the parts which need to be corrected . How should i go about doing it ?
One ambiguity is that whether you only want to know the difference between your template and test image or you want to detect letter A by using your template.
As mentioned by you, the difference between your template and test image is of that extra line but i think there are more differences e.g template A is not made of straight lines rather including some curves as well but the test 1 image is approximately made up of straight lines.
These two are different problems in image processing and must be entertained differently. First you have to think what you want to do?
However, one solution is that You can divide the template and test image in sub blocks and try to find the correlation between them, if that gives matching upto a predefined threshold( you should define it intelligently) than there is no difference otherwise mark that block as difference between the template and test image.
you can use xcorr2 function in MATLAB and MATLAB help is sufficient to understand the working of this function.

difference between ++i and i++ in for loop [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I understand well how postfix and prefix increments/decrements work. But my question is, in a for loop, which is more efficient or faster, and which is more commonly used and why?
Prefix?
for(i = 0; i < 3; ++i) {...}
Or postfix?
for(i = 0; i < 3; i++) {...}
For ints in this context there is no difference -- the compiler will emit the same code under most optimization levels (I'd venture to say even in the case of no optimization).
In other contexts, like with C++ class instances, there is some difference.
In this particular case, none is actually more efficient than the other. I would expect ++i to be more commonly used, because that's what would be more efficient for other kinds of iterations, like iterator objects.
In my opinion, choosing prefix or postfix in a for loop depends on the language itself. In c++ prefix is more efficient and consistent. Because in the prefix type, compiler does not need to copy of unincremented value. Besides your value must not be an integer, if your value is an object than this prefix type is more powerful.
Either works, and one is not more efficient or faster than the other in this case. It's common for people to use ++1, maybe because that is what was used in K&R and other influential books.

Name me a Binary Parser. A parser for binary data [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
So, I'm getting this data. From the network socket, or out of a file. I'm cobbling together code that will interpret the data. Read some bytes, check some flags, and some bytes indicate how much data follows. Read in that much data, rinse, repeat.
This task reminds me much to parsing source code. I'm comfy with lex/yacc and antlr, but they're not up to this task. You can't specify bits and raw bytes as tokens (well, maybe you could, but I wouldn't know how), and you can't coax them into "read two bytes, make them into an unsigned 16bit integer, call it n, and then read n bytes.".
Then again, when the spec of the protocol/data format is defined in a systematic manner (not all of them are), there should be a systematic way to read in data that is formatted according to the protocol. Right?
There's gotta be a tool that does that.
Kaitai Struct initiative have emerged recently to solve exactly that task: to generate binary parsers from a spec. You can provide a scheme for serialization of arbitrary data structure in a YAML/JSON-based format like that:
meta:
id: my_struct
endian: le
seq:
- id: some_int
type: u4
- id: some_string
type: str
encoding: UTF-8
size: some_int + 4
- id: another_int
type: u4
compile it using ksc (they provide a reference compiler implementation), and, voila, you've got a parser in any supported programming language, for example, in C++:
my_struct_t::my_struct_t(kaitai::kstream *p_io, kaitai::kstruct *p_parent, my_struct_t *p_root) : kaitai::kstruct(p_io) {
m__parent = p_parent;
m__root = this;
m_some_int = m__io->read_u4le();
m_some_string = m__io->read_str_byte_limit((some_int() + 4), "UTF-8");
m_another_int = m__io->read_u4le();
}
or in Java:
private void _parse() throws IOException {
this.someInt = this._io.readU4le();
this.someString = this._io.readStrByteLimit((someInt() + 4), "UTF-8");
this.anotherInt = this._io.readU4le();
}
After adding that to your project, it provides a very intuitive API like that (an example in Java, but they support more languages):
// given file.dat contains 01 00 00 00|41 42 43 44|07 01 00 00
MyStruct s = MyStruct.fromFile("path/to/file.dat");
s.someString() // => "ABCD"
s.anotherInt() // => 263 = 0x107
It supports different endianness, conditional structures, substructures, etc, and lots more. Pretty complex data structures, such as PNG image file format or PE executable can be parsed.
You may try to employ Boost.Spirit (v2) which has recently got binary parsing tools, endianness-aware native and mixed parsers
// This is not a complete and useful example, but just illustration that parsing
// of raw binary to real data components is possible
typedef boost::uint8_t byte_t;
byte_t raw[16] = { 0 };
char const* hex = "01010000005839B4C876BEF33F83C0CA";
my_custom_hex_to_bytes(hex, raw, 16);
// parse raw binary stream bytes to 4 separate words
boost::uint32_t word(0);
byte_t* beg = raw;
boost::spirit::qi::parse(beg, beg + 16, boost::spirit::qi::dword, word))
UPDATE: I found similar question, where Joel de Guzman confirms in his answer availability of binary parsers: Can Boost Spirit be used to parse byte stream data?
The Construct parser, written in Python, has done some interesting work in this field.
The project has had a number of authors, and periods of stagnation, but as of 2017 it seems to be more active again.
Read up on ASN.1. If you can describe the binary data in its terms, you can then use various available kits. Not for the faint of heart.
https://github.com/lonelybug/ddprotocol/wiki/Getting-Start
hope this is helpful to you.
There is certainly nothing stopping you from writing a recursive decent parser, say, for binary data the same way you would hand-tool a text parser. If the format you need to read is not too complicated this is a reasonable way to proceed.
Of course, if you format is very simple you could take a look at Reading binary file defined by a struct and similar question.
I don't know of any parser generators for non-text input, though those are also possible.
In the event that you are not familiar with coding parsers by hand, the canonical SO question is Learning to write a compiler. The Crenshaw tutorial (and in PDF) is a fast read.
See also google protocol buffers.
There is a tool called binpac that does exactly this.
http://www.icsi.berkeley.edu/pubs/networking/binpacIMC06.pdf

Phone number format and validation library [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
This question asking for a phone number format API in Java got me wondering why such an API doesn't seem to exist. Given the number of validation classes available under Apache Commons, I would have thought such an API would be included.
My question is, does anyone know of a phone number formatting/validation library available in any language that could be used as a model for a small Java open source project? Also, other than the large number of different phone number formats used throughout the world, does anyone know of any reason that such a project would be infeasible?
Google recently released libphonenumber for parsing, formatting, storing and validating international phone numbers.
Such an API in any language: Number::Phone (example submodule: Number::Phone::US).
Data: the ITU's National Numbering Plans index.
At http://www.geonames.org/ they have a database you can download, theres regEx rules for phone numbers included in the country info dataset.
http://download.geonames.org/export/dump/
Look for the 'countryInfo.txt' file.
I suggest you build your own validator based upon that.
Like it was said in the answers to the other question, no one's seen any for Java, and like you said, it would be nearly impossible due to the difference of phone number formats across the world.
And if you know the different formats for the regions that you're targeting, then it's usually pretty easy to implement it in regular expressions.
You can check out Parsify Format here - https://www.mashape.com/parsify/format#endpoint-Phone-Number
It will return your number in several formats e.g.
{
"e164": "+1234567890",
"national": "234567890",
"international": "+1 234567890",
"valid": false,
"type": "UNKNOWN"
}
You can get a more extensive response if it's a real number
Phone Input field :
<input class="left" id="field" name="field" />
jquery Script:
jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
phone_number = phone_number.replace(/\s+/g, "");
return this.optional(element) || phone_number.length > 9 &&
phone_number.match(/^(1-?)?(([2-9]\d{2})|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");

Resources