|
So, you have all the information you need, time to get started. If you were under the mistaken impression that someone here was going to do your work for you ...
|
|
|
|
|
You are not asking a specific question. You are essentially asking someone to do all the work for you, which will not happen.
Get started on it and if you get stuck on something specific then come back and show where you are stuck and someone will be glad to help.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Member 14956475 wrote: I have to implement the Blum Blum Shub in C or C++... More importantly, can you do it with pencil and paper? If the answer is no, then: 1) you are going to be hard pressed to implement it in code, and 2) you should work on it until you can produce results on paper. Don't let computer code take the place of the basic understanding of algorithms.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Okay , this is the code that i managed to do :
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
const int p = 30000000091;
const int q = 40000000003;
int N ;
scanf("%i", &N);
const unsigned long long int s = 1200000003730000000273;
unsigned int i,M,x[N];
time_t t;
srand((unsigned) time(&t));
M=p*q;
i=0;
x[0]=s;
for(i=1;i<=N;i++){
x[i]=(x[i-1]*x[i-1])%M;
}
for(i=1;i<=N;i++){
printf(" x[%d] = %d\n",i,x[i]);
}
system("PAUSE");
return 0;
}
I have some issues with it , first it's that i need to add from console the biggest number D and i dont know how to put it in as now it's generating numbers without upper limit . Also can anyone tell me how to fix the code as it generates the same numbers at some intervals , if you have other remarks on how to make it better tell me please . Thanks
|
|
|
|
|
I found at least one issue with the code:
You're using the variable N before you initialize it with a value. This is a no no.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Member 14956475 wrote: ...i need to add from console the biggest number D and i dont know how to put it in as now it's generating numbers without upper limit . Change your main() signature to:
void main( int argc, char *argv[] ) Then access argv[1] to get D as a command line argument.
Also, your two for() loops are accessing beyond the end of the x array. In C, arrays start at 0 .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I've replaced main() with
void main( int argc, char *argv[] ) , but how can i acces argv[1] to get D as a command line argument?
modified 7-Oct-20 13:31pm.
|
|
|
|
|
Member 14956475 wrote: ...but how can i acces argv[1] to get D as a command line argument? The same way you would access parameters from within any other function. main() is no different. See here for more.
Member 14956475 wrote: ...is it possible to use srand command? Your code is already doing that. However, the way in which you are using it is meaningless since you are also not calling rand() . rand() by itself will always generate the same sequence of numbers. srand() will "seed" the number generation process to start at a different spot.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/*BLUM BLUM SHUB*/
int main ()
{
const int p = 347;
const int q = 351;
const unsigned long long int s = 12373273;
int N ;
printf("enter the number:");
scanf("%i", &N);
unsigned int i,M,x[N];
srand(time(NULL));
M=p*q;
i=0;
x[0]=s;
for(i=1;i<=N;i++){
x[i]=rand()*(x[i-1]*x[i-1])%M;
}
for(i=1;i<=N;i++){
printf("%d\t",x[i]);
}
system("PAUSE");
return 0;
}
I added srand and rand is it okay working now ?
|
|
|
|
|
Member 14956475 wrote: is it okay working now ? Only you can determine that.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Okay , so this is the final code that i have at the moment
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/*BLUM BLUM SHUB*/
int main ()
{
const int p = 347;
const int q = 351;
const unsigned long long int s = 12373273;
int N ;
printf("Introdu numarul de cifre aleatorii:");
scanf("%i", &N);
unsigned int i,M,x[N];
srand(time(NULL));
M=p*q;
i=0;
x[0]=s;
FILE *fp; //txt code
fp = fopen("file.txt", "w"); //txt code
for(i=1;i<=N;i++){
x[i]=rand()*(x[i-1]*x[i-1])%M;
}
for(i=1;i<=N;i++){
printf("%d\t",x[i]);
fprintf(fp, "%d ",x[i]); //txt code
}
system("PAUSE");
fclose(fp);//txt code
return 0;
}
It's working but i have one issue that i can't still solve , i need to put a maximal limit of the generated numbers at input , can anyone give me a clue how i can set x[i] a limit? I only found how to put a limit at rand but when it multiplies with function of BBS it exceeds the limit
|
|
|
|
|
That should already work, but you can add another set of parenthesis to make sure:
x[i] = (rand() * (x[i-1] * x[i-1])) % M;
So the random number times the square of x[i-1] should be calculated first.
|
|
|
|
|
Hi,
I have a Win32 application written in C and compiled by MS Visual Studio 2017 Community Edition.
My application has no problem to print on a dot matrix printer.
But, it has problem when trying to print on Inkjet printer.
My application fails to select a font type, change the font size or condensed through printer Escape character (Epson).
Could you please help?
Thank you.
Cheers,
Sandford
|
|
|
|
|
sandford_j wrote:
My application fails to select a font type, change the font size or condensed... Do these features work on the dot matrix printer?
sandford_j wrote: Could you please help? Without seeing any code? How would you propose we do this?
What sort of error checking do you have in place? Have you eliminated all the code except that which is absolutely necessary to reproduce the problem?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi David,
Font selection, font size and condensed printing work with dot matrix printer that support Esc/P.
Unpredictable problems occur when trying to print on Inkjet printers such as:
1. The printer ignores the font type, font size and condensed printing.
2. Both Epson WF-7611 and HP OfficeJet Pro do not accept "RAW" for the data type in "StartDocPrinter" parameter. Epson WF-7611 will only accept "Text", while HP OfficeJet Pro only accept "XPS_XPSS". This means I have to detect what printer to print before assigning the data type.
3. The Win32 Printing API says that calling "EndPagePrinter" will end the current page, but it doesn't work that way.
Thank you.
Sandford
Please refer to the code below:
BOOL testPrint (char dataToPrint []) {
char pName [1024];
DWORD level,
sizeof_pName;
HANDLE hPrinter;
DOC_INFO_1 DocInfo;
DWORD dwJob;
DWORD dwBytesToPrint,
dwBytesPrinted;
sizeof_pName = sizeof(pName);
memset (pName, 0, sizeof(pName));
if (!GetDefaultPrinter(pName, &sizeof_pName)) {
printf ("Fail to GetDefaultPrinter. ");
return FALSE;
}
if(!OpenPrinter (pName, &hPrinter, NULL)) {
printf ("Fail to OpenPrinter [%s]. ", pName);
return FALSE;
}
level = 1;
DocInfo.pDocName = "My Document";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = "TEXT";
if((dwJob = StartDocPrinter(hPrinter, level, (LPSTR)&DocInfo)) == 0) {
ClosePrinter (hPrinter);
printf ("Fail to StartDocPrinter [%s]. ", pName);
return FALSE;
}
if(!StartPagePrinter (hPrinter)) {
EndDocPrinter (hPrinter);
ClosePrinter (hPrinter);
printf ("Fail to StartPagePrinter [%s]. ", pName;
return FALSE;
}
dwBytesToPrint = strlen(dataToPrint);
if(!WritePrinter (hPrinter, dataToPrint, dwBytesToPrint, &dwBytesPrinted)) {
EndPagePrinter (hPrinter);
EndDocPrinter (hPrinter);
ClosePrinter (hPrinter);
printf ("Fail to WritePrinter [%s]. ", pName);
return FALSE;
}
if(!EndPagePrinter (hPrinter)) {
EndDocPrinter (hPrinter);
ClosePrinter (hPrinter);
printf ("Fail to EndPagePrinter [%s]. ", pName);
return FALSE;
}
if(dwBytesPrinted != dwBytesToPrint) {
printf ("Fail to print [%s] to [%s]. ", dataToPrint, pName);
return FALSE;
}
if(!EndDocPrinter(hPrinter)) {
ClosePrinter(hPrinter);
printf ("Fail to EndDocPrinter [%s]. ", pName);
return FALSE;
}
ClosePrinter(hPrinter);
return TRUE;
}
|
|
|
|
|
As Esc/P is an older technology only supported by a few printers, have you considered using PCL instead?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I did try to use PCL6 but fail.
I send the PCL command by calling WritePrinter API.
I do not know if I need to call another Win32 Printing API to send the PCL command.
The PCL command is arranged in an array of bytes. But, no response from the printer.
Any code sample to send PCL command, please?
Thank you.
Sandford
|
|
|
|
|
|
Hi Gerry,
Thanks. I will try.
Sandford
|
|
|
|
|
Just a suggestion if you get really desperate; If the printer has a hex dump mode feature you can enable it and print out exactly what's being sent to the printer. Another way is to set the printer driver to 'Print to File' and your job will print to a file. Then if you are familiar with the printer language, you can examine the data to see if something has been added or missing in the printer data stream.
Good luck
|
|
|
|
|
|
I found some old code that I wrote some time ago but never tested. I did a quick test with it and found that when I printed to my hp laserjet that I was only getting 1/2 of the data. After a little investigating I found that i didn't adjust for unicode data so using "RAW" mode passing 2 * datasize to
WritePrinter((void*)data, 2*datasize, &dwBytesWritten)
seem to fix the problem. However, as I said, this code is not fully tested so don't know if this is a real fix or if it has anything to do with your problem. I have problem using "TEXT" mode also but don't feel like investigating. The documentation just says "size of the array". Doesn't mention anything about unicode.
Test data _T("abcd")
Sending a size of 4 resulted in "ab" printing out.
Sending a size of 8 resulted in "abcd" printing out.
Also, if your printer data escape sequence as nul values in it, you may have to adjust it for unicode; ie. double nul.
_T("escN") + nul + nul
Best regards.
-- modified 1-Oct-20 8:17am.
|
|
|
|
|
|
Hi~
I wrote the following function to copy the selected part of NotePad.
( Sending Control+C Message )
However, it does not work!
Only 'C' is printed in NotePad.
Does anyone know why?
>> OS : Windows10
>> Compiler : VisualStudio 2010
Send_KeyBoard_Control_C()
{
HWND notepad = ::FindWindow(__T("NotePad"), NULL );
if (notepad == NULL) {
return;
}
if (!::SetForegroundWindow(notepad)) {
return;
}
int sendCount = 0;
INPUT input;
ZeroMemory(&input, sizeof(INPUT));
input.type = INPUT_KEYBOARD;
input.ki.wVk = VK_CONTROL;
input.ki.wScan = 0;
input.ki.dwFlags = 0;
sendCount += SendInput(1, &input, sizeof(INPUT));
ZeroMemory(&input, sizeof(INPUT));
input.type = INPUT_KEYBOARD;
input.ki.wScan = 'C';
input.ki.dwFlags = KEYEVENTF_UNICODE;
sendCount += SendInput(1, &input, sizeof(INPUT));
ZeroMemory(&input, sizeof(INPUT));
input.type = INPUT_KEYBOARD;
input.ki.wScan = 'C';
input.ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
sendCount += SendInput(1, &input, sizeof(INPUT));
ZeroMemory(&input, sizeof(INPUT));
input.type = INPUT_KEYBOARD;
input.ki.wVk = VK_CONTROL;
input.ki.wScan = 0;
input.ki.dwFlags = KEYEVENTF_KEYUP;
sendCount += SendInput(1, &input, sizeof(INPUT));
if ( sendCount != 4 ) {
TRACE("fail\n");
}
}
modified 30-Sep-20 6:56am.
|
|
|
|
|
Why are you using KEYEVENTF_UNICODE flag?
|
|
|
|