

I am going to implementing my own new query language for retrieving the web data. For that purpose i need an efficient algorithm for design new <b>parser</b>. What will the steps to design new parser.





Find a tokenizer and learn the interpreterpattern.





First step of course is to design the language.
Other than that, generally parsers do not need to be efficient because parsing shouldn't be significant, rather running should be. And that would be interpretation or execution.





You may have a look at flex/bison, generating lexical scanner and parser (formerly known as lex/yacc).





i am doing a language translation app to convert trini vernacular in to standard english.. i have just started.. i am considering to use the boyer more algorithm to do the matching.. is this a good idea? and what else can any one suggest?





Boyer Moore string searching is efficient for searching large volumes of text, but translation usually involves more than just mechanically replacing one set of strings with another. You might want to look at Lex and Yacc, e.g. http://dinosaur.compilertools.net/[^]






can any bady help me I need the AES algorithm code plzzzzzzzzzzzzzzzzzzzzzzzzzz





I'm sure some good soul will be along soon but while you're waiting try typing "AES algorithm" into Google or Bing.






using System;
using System.IO;
using System.Security.Cryptography;
namespace Aes_Example
{
class AesExample
{
public static void Main()
{
try
{
string original = "Here is some data to encrypt!";
using (AesManaged myAes = new AesManaged())
{
byte[] encrypted = EncryptStringToBytes_Aes(original, myAes.Key, myAes.IV);
string roundtrip = DecryptStringFromBytes_Aes(encrypted, myAes.Key, myAes.IV);
Console.WriteLine("Original: {0}", original);
Console.WriteLine("Round Trip: {0}", roundtrip);
}
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
}
}
static byte[] EncryptStringToBytes_Aes(string plainText, byte[] Key, byte[] IV)
{
if (plainText == null  plainText.Length <= 0)
throw new ArgumentNullException("plainText");
if (Key == null  Key.Length <= 0)
throw new ArgumentNullException("Key");
if (IV == null  IV.Length <= 0)
throw new ArgumentNullException("Key");
byte[] encrypted;
using (AesManaged aesAlg = new AesManaged())
{
aesAlg.Key = Key;
aesAlg.IV = IV;
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msEncrypt = new MemoryStream())
{
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
swEncrypt.Write(plainText);
}
encrypted = msEncrypt.ToArray();
}
}
}
return encrypted;
}
static string DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV)
{
if (cipherText == null  cipherText.Length <= 0)
throw new ArgumentNullException("cipherText");
if (Key == null  Key.Length <= 0)
throw new ArgumentNullException("Key");
if (IV == null  IV.Length <= 0)
throw new ArgumentNullException("Key");
string plaintext = null;
using (AesManaged aesAlg = new AesManaged())
{
aesAlg.Key = Key;
aesAlg.IV = IV;
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msDecrypt = new MemoryStream(cipherText))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
{
plaintext = srDecrypt.ReadToEnd();
}
}
}
}
return plaintext;
}
}
}
Cheees,
Edo





I'm trying to code the Secure Remote Password protocol (RFC 2945). I wasn't sure if I was getting the correct values at each stage so I did some searching and came across RFC 5054 which supplies some test vectors. I believe my problem is coming from the conversions between hex string, integers, bytes, and BigIntegers, however I just can't seem to track it down. Below is just one parameter that I need to calculate, but since all the other parameters are calculated in a similar way, if I can get this one working, all the rest should be fine.
Parameters
N  Large 1,024 bit safe prime number. The hex value is:
EEAF0AB9 ADB38DD6 9C33F80A FA8FC5E8 60726187 75FF3C0B 9EA2314C
9C256576 D674DF74 96EA81D3 383B4813 D692C6E0 E0D5D8E2 50B98BE4
8E495C1D 6089DAD1 5DC7D7B4 6154D6B6 CE8EF4AD 69B15D49 82559B29
7BCF1885 C529F566 660E57EC 68EDBC3C 05726CC0 2FD4CBF4 976EAA9A
FD5138FE 8376435B 9FC61D2F C0EB06E3
g  A generator of N with a value of 2
a  Private random number. Test vector provides the following to use:
60975527 035CF2AD 1989806F 0407210B C81EDC04 E2762A56 AFD529DD
DA2D4393
A  Public value I'm trying to computer. A = g^a % N
Obviously these are large numbers to be working with, so I'm using the BigInteger class from the System.Numeric namespace in VB.NET 4. I'm tried many different ways to get this to work. Below is my latest incarnation of the code trying to compute A:
Dim strN As String = "EEAF0AB9ADB38DD69C33F80AFA8FC5E86072618775FF3C0B9EA2314C" & _
"9C256576D674DF7496EA81D3383B4813D692C6E0E0D5D8E250B98BE4" & _
"8E495C1D6089DAD15DC7D7B46154D6B6CE8EF4AD69B15D4982559B29" & _
"7BCF1885C529F566660E57EC68EDBC3C05726CC02FD4CBF4976EAA9A" & _
"FD5138FE8376435B9FC61D2FC0EB06E3"
Dim N As BigInteger = BigInteger.Parse(strN, Globalization.NumberStyles.HexNumber)
Dim g As New BigInteger(2)
Dim private_a_hex As String = "60975527035CF2AD1989806F0407210BC81EDC04E2762A56AFD529DDDA2D4393"
Dim private_a As BigInteger = BigInteger.Parse(private_a_hex, Globalization.NumberStyles.HexNumber)
Dim public_A As BigInteger = BigInteger.ModPow(g, private_a, N)
Dim public_A_hex As String = public_A.ToString("X")
When I run the above code public_A_hex (which is hold the value of A), I'm getting the following hex string:
0CB3B3D1 59B9DFD8 7D5995E2 BAF4D4DC E8A27402 B388652E 133E4A67
2D63FAE8 D432E166 2C2A23A3 8E67D164 49282934 20AC0693 7F3182F5
3EB21DA2 5CE20CCB 27075CCB 21664335 9CFB2816 7B378F9A F0F9534F
6A2BB9E8 9A5FEAD2 38DFDF7C ABDB747B FEB127CB 9E4A08DF 08D813F5
D874B65B 9D43AAAD 102700BC 160365F7
However RFC 5054 says that A should be the follow:
61D5E490 F6F1B795 47B0704C 436F523D D0E560F0 C64115BB 72557EC4
4352E890 3211C046 92272D8B 2D1A5358 A2CF1B6E 0BFCF99F 921530EC
8E393561 79EAE45E 42BA92AE ACED8251 71E1E8B9 AF6D9C03 E1327F44
BE087EF0 6530E69F 66615261 EEF54073 CA11CF58 58F0EDFD FE15EFEA
B349EF5D 76988A36 72FAC47B 0769447B
I'm thinking the error is coming from the endianness of the byte arrays/hex strings; I've tried reversing arrays before and after each conversion with still no luck. I don't know where to go from here at this point as I've been working on this for a little over 2 days.
I know that there are some libraries out there, but at this point I don't want to use them. Since the values don't work out, and I can't figure out why, I would like to know what I'm doing wrong and improve my knowledge in the process.
Any help or guidance would be greatly appreciated.
Thanks,
Dominick





There's a problem there. The number
EEAF0AB9 ADB38DD6 9C33F80A FA8FC5E8 60726187 75FF3C0B 9EA2314C
9C256576 D674DF74 96EA81D3 383B4813 D692C6E0 E0D5D8E2 50B98BE4
8E495C1D 6089DAD1 5DC7D7B4 6154D6B6 CE8EF4AD 69B15D49 82559B29
7BCF1885 C529F566 660E57EC 68EDBC3C 05726CC0 2FD4CBF4 976EAA9A
FD5138FE 8376435B 9FC61D2F C0EB06E3
as interpreted with E3 being the lowest byte and EE the highest, is not a prime number. It's divisible by 2609.
That same number interpreted as EE being the low byte and 3E the high byte (ie the stringreverse), is not an prime either, rather trivially, since E is even.
I have tried other arrangements, but I have yet to find one that's actually prime.
Chances are that the other numbers are using some weird order as well.





Thanks for the responese however, after burning through the night and checking the code hundreds of time, I found the issue. It turned out that the number was being interpreted as a negative number by the BigInteger class. Once I added a 0 to the beginning of the prime number the code worked and matched up with all the test vector's outputs.





Makes sense, I should probably have thought of that





Hello,
I try to find some code related Robot voice but not success. Please give me some code to change voice to Robot voice.
About FFT, where I find FFT library for android?
Thanks!
Please help me to complete it.





FFTW[^] is in C, so you should be able to tie it into any platform easily.
As far as the robot voice deal...





He's looking for a phase vocoder.





So why are you telling me? ...maybe you should tell the OP.





Hi! I've to print the index of a selected cell in a Table. The table has eight rows and eight columns. The rows are labled from A to H and the cloumns are labled from 1 to 8. If I click the cell in the first row and first column I've to print A1. Similarly If I click the cell in the first row and Second column I've to print B1 My function has to return the index of each and every cell in the table. How to code that function in C++?





char rowLetter = 'A' + selectedCell.row;
int columnNumber = selectedCell.column + 1;
cout << rowLetter << columNumber << endl;
printf("%c%d\n", rowLetter, columNumber);
One of these days I'm going to think of a really clever signature.





I am trying to do a problem of solid waste collection vehicle routing using Genetic algorithm in C++. So here raises the question why should I use GA. How do I defense this question? My main logic is solid waste collection problem is a non linear problem thats why for solving it I chose GA. So can it be like I can form a model to prove its non linearity? If its modeling is possible what things do I need to focus?





Need more detail on the routing problem to give a more detailed answer. But GAs are useful when combining parts of good solutions give you better solutions.
"Microsoft  Adding unnecessary complexity to your work since 1987!"





My client is asking for a copy of the algorithm for his programme should I give it up or should I keep it?





Probably depends on the specific of the question.
For example if they wanted you to implement a backpack solution and it was specifically phrased like that as part of the contract (via perhaps associated requirements) then it might be reasonable to document which one you chose but not provide how you implemented it.
However if you implemented a standard business application and there are no specific contractual (or implicitly contractual requirements because it wasn't explicit) and thus the customer thinks you should give then the source code  then no.
In general
1 Is there a specific contractual obligation
2 How significant is the algorithm in terms of the work product.
3 What is your business relationship with the client? So for example if you expect to get jobs from them for the next 10 years then you might want to give something up. But if you want to sell the product to 10 competitors to the client then probably not.





Thank you for your answer.1) There was no contractual obligation at the start of writing the source code, only after I had started was this asked for.
2)Without the algorithm the programe wouldn't work in anyway.3) first time I have worked for this client, he is proving most troublesome and I cannot see any need for me in the next ten years (although a memeber of his team is planning on jumping ship and maybe taking me with him).





In the UK when working with the UK Government, you have to keep the bespoke source code with a trusted third party (e.g. a solicitor, with the source code on a CD/memory stick). The UK Government can only access that source code if the bespoke software development company fails. This allows the UK Government to keep its investment secure as they can take the source code to another bespoke development company, if needed.
Hope that provides an alternative solution which may be acceptable to your client.
www.styletech.co.uk





I first noticed this when I was in high school. But I can't seem to find any references to it on the Internet, did I discover something previously unknown?
I'm sure the algorithm can be made more efficient using other rules for generating prime numbers, but I'm just curious if anyone has even seen this before, and who (if not me), first discovered this.
How I'm generate prime numbers...
1. 2 is not include
2. Insert 3 and 5 into the prime number set
3. The next prime number is 7 = 5 + 3  1
4. The next prime number is 11 = 7 + 5  1
5. The next prime number is 13 = 11 + 3  1
So (Next Prime) = (Last Prime) + (Some Smaller Prime)  1
Here is some C# code, showing this...
void Test()
{
List<long> primeNumbers = new List<long>();
primeNumbers.Add(3);
primeNumbers.Add(5);
DateTime stopTime = DateTime.Now + new TimeSpan(0, 10, 0);
Console.Write("Calculating prime numbers...");
while (DateTime.Now < stopTime)
{
if (primeNumbers.Count % 100 == 0)
Console.Write(".");
primeNumbers.Add(GetNextPrime(primeNumbers));
}
Console.WriteLine("Calculated " + primeNumbers.Count + " prime numbers.");
Console.WriteLine("The largest being " + primeNumbers.Last() + ".");
}
long GetNextPrime(List<long> primeNumbers)
{
long lastPrime = primeNumbers.Last();
for (int i = 0; i < primeNumbers.Count  1; i++)
{
long testValue = lastPrime + primeNumbers[i]  1;
bool fail = false;
for (int j = 0; j < primeNumbers.Count  1; j++)
{
if (testValue % primeNumbers[j] == 0)
{
fail = true;
break;
}
}
if (fail) continue;
return testValue;
}
throw new Exception("Rule failed");
}





There is no simple algorithm for generating prime numbers. For example, your method falls apart when you take the next step: 11 + 5  1 = 15, which isn't prime.
A foolproof (but slower) method is to try dividing a candidate by all the integers up to the square root of that number. If none can divide it evenly, it's prime.
Also look at: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes[^]
"Microsoft  Adding unnecessary complexity to your work since 1987!"





Hello there,
Prime Number Generating Algorithm:
A Prime Sieve or Prime Number Sieve is defined to be a fast type of algorithm for finding prime numbers. There are quite a lot of prime sieves that can be found. So the question remains: which one should I implement?
First we must ask: exactly how does a Prime Sieve work? What does it do? Well, here's the answer! A prime sieve works by creating a list of all integers up to a what ever limit and then progressively removing numbers that are made up of multiple elements (composite)until only primes numbers remain. This is one of the most known the most efficient ways to obtain a large range of prime numbers.
Live Support Software for Busines
April
Comm100  Leading Live Chat Software Provider
modified 27May14 8:40am.





Hi
The catch with prime numbers is that to this day there's no algorithm that will find them all in any given interval without resorting to any form of trial and error or anyway without making any comparison against a set of pregress data.
Unbelievable as it sounds, that's the current truth.
Should you discover such an algorithm it'd earn you both a Nobel and a very fat place in hystory, hands down.
Keep trying and keep hoping ; )





In a CAD program, I want to find the (vector) entities that bound a given point.
1) Is a seed fill type algorithm the best choice for this? Or is there a quicker / better / more efficient method?
2) Once I've found my bounding entities, can I make my 'is the boundary contiguous' check fault tolerant to some degree? And what approach would be best? If my line ends aren't coincident, for instance, I could perhaps extended them be a certain tolerance to see if they 'almost cross'? (and then use the 'virtual' vertex in my bonding shape)
Cheers





A kd tree ([^]) is good for nearestneighbor and range searches.
It's like a standard binary search tree, except the discriminant (the value you use to decide on the left or right branches) alternates between the X and Y coordinates at each level.
So at each level, you can eliminate half the search space, depending on if the X or Y coordinates are beyond the point you're searching around. (If neither can be eliminated, you recursively search down both the left and right branches.)
Once you have the entities that are clustered around your point, you can check if they overlap to detect a contiguous entity path around the point.
"Microsoft  Adding unnecessary complexity to your work since 1987!"





I have path which is in '*' (asterisk) shape. All the ends are the nodes such that there is 8nodes and one node in the center. I want to form an algorithm that could start the journey from one end and travel to all the other nodes.Can any one guide me through this. How should i proceed the coding?





There are many ways to do this. Probably the simplest is depthfirst search, which visits each unvisited node connected to the current node, recursively.
To implement this, you need a Boolean "visited" member of the node structure, which is initially false in all nodes.
You call the search function with any node to start. The function then sets "visited" to true, and calls itself recursively with each of the node's unvisited neighbors. When it returns at the top level, you've visited all the nodes.
"Microsoft  Adding unnecessary complexity to your work since 1987!"





Hello,
Please put a picture of the shape that shows the nodes and paths (lines connecting the nodes) An asterisk has six points, not eight. Maybe you mean a star, then people need to know if you are including the inside corners.





Dear members,I am trying to do optimization of water supply network by using particle swarm optimization method,and I have the objective function but my problem is how I can use PSO in Matlab,I have tried to download some codes,but still is difficult for me to use it since I am new in optimization,please any help





I am trying to do problem in which i have numbers of points. Now i need to find the path that goes through all the points. This is not actually TSP because as per my knowledge in TSP it is possible to travel from all points to every other points. But in my case the path network is fixed and i just need to find the path that goes through all the points provided that all points may not have connection to every other point..so what algorithm am i supposed to follow.





Go ask our friends Google and Wikipedia about "spanning tree". That will get you started, and probably almost finished too.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012





Hello,
So how's it coming along? Do you understand the concept?
With Kind Regards,
April
Comm100  Leading Live Chat Software Provider
modified 27May14 8:35am.





Hello All. I own a classified ad site and need several things done to correct and update the code of the site. A nightmare for me, probable only a few days work for you. who ever can do the work will get life time ads space on my site and on my new sites when they go in to production. when completed the newly updated site will be promote world wide , and will have 975 cities listed on it, your ad will be in the computer and code section for the freelancers and it will be listed in all 975 cities! I will consider more than one code warrior for this gig in case the work i need is too much for one person. all involved in the work will get free, life time ad space, which they can sublet if they want and make a profit. interested parties should contact me here. the name of my active site is : Beyslist.com Thanks Everyone.





does any one here have any idea of the possibility of creating a classified ad aggregation Algorithm, i am designing a new classified ad service and need in put. we will need such an Algorithm created if we are to move forward, any comments welcome. thanks. M Bey





For the very large number like 2^2000 how do I calculate its value?





Use logarithms.
"Microsoft  Adding unnecessary complexity to your work since 1987!"






To elaborate on Alan's suggestion...
Let's take a big power of 2, such as:
2 ^ 2000
We first reexpress it using a power of 10:
10 ^ (2000 * log10 (2))
Which yields:
10 ^ 602.05999132796239042747778944899
But we want it reexpressed in the more useful form of: man * 10^exp, the scientific notation (just in case).
We know that x^(a+b) == (x^a) * (x^b), where x=10 and (conveniently) a and b can be the integer and the fractional parts of 602.05999132796239042747778944899
In other words:
10 ^ (602 + 0.05999132796239042747778944899) == (10 ^ 602) * (10 ^ 0.05999132796239042747778944899)
We can rearrange it in:
10 ^ 0.05999132796239042747778944899 * 10 ^ 602
Which yields:
1.1481306952742545242328332011881 * 10 ^ 602
And that's the result of 2 ^ 2000:
1.1481306952742545242328332011881e+602
You may calculate this with fixed math, but you won't get as many ULPs and it'll take more time. Either way you're going to get an approximation of the sought value.
The above also works with smaller powers.
A quick demonstration for:
5^3 = 125
Here:
5^3 = 10 ^ (3 * log10 (5))
5^3 = 10 ^ 2.0969100130080564143587833158265
5^3 = 10 ^ (2 + 0.0969100130080564143587833158265)
5^3 = (10 ^ 2) * (10 ^ 0.0969100130080564143587833158265)
5^3 = 10 ^ 0.0969100130080564143587833158265 * 10 ^ 2
5^3 = 1.2499999999999999999999999999985 * 10 ^ 2
5^3 = 1.2499999999999999999999999999985e+2
If we account for the rounding error it becomes familiar:
5^3 = 1.25e+2
5^3 = 125
[edited to improve explanation]
modified 23Oct12 6:43am.





my friend you can use the big integer class it helps you a lot to do such things.





Use binary:
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b





More seriously, an easy option is to work in base 1 billion, using an array of integers. Every integer will store 9 significant decimal digits.
It is a rather straightforward matter to implement a doubling algorithm, by means of long addition, as in the following quick Python code.
N= [0] * (Digits  1) + [1] # Large number representation of 1
for Exponent in range(2000): # Double 2000 times
for Position in range(Digits): # For all digits
N[Position]= 2 * N[Position] # Double this digit
if N[Position] >= Base: # Detect carry out
N[Position]= Base # Adjust the digit...
N[Position  1]+= 1 # ... and carry out to the left one
print N
Output:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114813069, 527425452, 423283320, 117768198, 402231770, 208869520, 47764273, 682576626, 139237031, 385665948, 631650626, 991844596, 463898746, 277344711, 896086305, 533142593, 135616665, 318539129, 989145312, 280000688, 779148240, 44871428, 926990063, 486244781, 615463646, 388363947, 317026040, 466353970, 904996558, 162398808, 944629605, 623311649, 536164221, 970332681, 344168908, 984458505, 602379484, 807914058, 900934776, 500429002, 716706625, 830522008, 132236281, 291761267, 883317206, 598995396, 418127021, 779858404, 42159853, 183251540, 889433902, 91920554, 957783589, 672039160, 81957216, 630582755, 380425583, 726015528, 348786419, 432054508, 915275783, 882625175, 435528800, 822842770, 817965453, 762184851, 149029376]
In reality, this algorithm uses a trick: a carryin to a digit (from the right) will never cause a carryout (to the left). This is because the doubled digits are even, at most 999999998, and can stand one incrementation. This allows us to process lefttoright. This property doesn't hold for plain addition where carries can propagate further.
A more efficient but a little more complex solution can be achieved by using a base conversion algorithm.
modified 3Dec12 6:44am.





There is actually a subtle bug in your code. If, on the last pass of your outer loop, one "digit" is == Base  1 and you carry into it, you never get to carry out of it. If you write your inner loop backwards (or reverse your array), it all comes out in the wash... The point is that multiprecision add/subtract should be done "right to left" so multiplace carry propagation can occur naturally.
A small point, but still important. The one time it bit me, the code was in ROM inside tamperproof enclosures. A real PITA to fix...
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012




