Autor Beitrag
traceurmicha
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 160
Erhaltene Danke: 9

Win XP SP2, Win 7 Pro., Ubuntu 9, Debian 5
C#, ASP.NET, MSSQL, PHP(Microsoft Visual Studio 2010 Ultimate, SharpDevelop 4, Microsoft SQL Server2008 Express, Eclipse for PHP)
BeitragVerfasst: Di 01.03.11 13:58 
Ja tut mir leid ich muss nochmal mit C nerven^^

nur eine Frage:
ich habe folgenden Quelltext:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
#include <stdbool.h>
...
bool isPrime(int Number)
{
    for(int i = 2;i<=Number-1;i++)
    {
        if(Number%i == 0)
        {
            return false;
        }
    }
    return true;
}


wenn ich diesen Code Kompilieren will meckert der Compiler bei bool isPrime(int Number) mit der Fehlermeldung "error: conflicting types for 'isPrime'

auch das tauschen von bool mit _Bool hat nix gebracht.

Kann mir jemand helfen?

_________________
Programmieren ist ein Rennen zwischen den Softwareentwicklern, die versuchen größere und bessere idiotensichere Programme zu schreiben und dem Universum, welches versucht größere und bessere Idioten zu produzieren. Zur Zeit liegt das Universum in Führung.


Zuletzt bearbeitet von traceurmicha am Di 01.03.11 16:05, insgesamt 1-mal bearbeitet
baka0815
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 489
Erhaltene Danke: 14

Win 10, Win 8, Debian GNU/Linux
Delphi 10.1 Berlin, Java, C#
BeitragVerfasst: Di 01.03.11 16:00 
Was ist "zahl" denn für eine Variable?
traceurmicha Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 160
Erhaltene Danke: 9

Win XP SP2, Win 7 Pro., Ubuntu 9, Debian 5
C#, ASP.NET, MSSQL, PHP(Microsoft Visual Studio 2010 Ultimate, SharpDevelop 4, Microsoft SQL Server2008 Express, Eclipse for PHP)
BeitragVerfasst: Di 01.03.11 16:06 
Sorry, da hatte ich mich verschrieben. Habs berichtigt!

_________________
Programmieren ist ein Rennen zwischen den Softwareentwicklern, die versuchen größere und bessere idiotensichere Programme zu schreiben und dem Universum, welches versucht größere und bessere Idioten zu produzieren. Zur Zeit liegt das Universum in Führung.
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Di 01.03.11 16:48 
Hey,

Ist das vlt eine standart-methode? Versuch mal nen anderen namen zu nehmen. Wenn das auch nicht geht versuch ma int als rückgabe und gib 0 oder 1 zurück.

Mfg Bergmann

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 01.03.11 19:19 
Unter C++ funktioniert das (ohne stdbool.h einzubinden) einwandfrei.

ausblenden Delphi-Quelltext
1:
for(int i = 2;i<=Number-1;i++)					

Es genügt die Schleife bis sqrt(Number) laufen zu lassen.
Zumal es auch sehr viel effzientere Verfahren gibt. :zustimm:

user profile iconBergmann89 hat folgendes geschrieben Zum zitierten Posting springen:
Ist das vlt eine standart-methode? Versuch mal nen anderen namen zu nehmen

Wie und wo rufst du denn die Methode auf? Ich würde nämlich auch darauf tippen, dass der Compiler eine nicht passende Signatur verwendet, weil bereits eine andere Deklaration exisitiert.
traceurmicha Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 160
Erhaltene Danke: 9

Win XP SP2, Win 7 Pro., Ubuntu 9, Debian 5
C#, ASP.NET, MSSQL, PHP(Microsoft Visual Studio 2010 Ultimate, SharpDevelop 4, Microsoft SQL Server2008 Express, Eclipse for PHP)
BeitragVerfasst: Do 03.03.11 10:00 
Also zum Besseren verständnis habe ich hier mal denn gesammten quelltext für euch. Habe isPrime auch in isPrimeN umbenannt hat aber auch nix geholfen.

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include <time.h>

int main()
{
    printf("RSA-Verschluesselung\n");
    Eingabe();
    return 0;
}

void Eingabe()
{
    int p,q,n,e,d;
    bool b_sizeOfValue = false;
    int bool_temp = 0;
    char M[5],c;
    bool test = isPrimeN(8);
    printf("%s",test);
while(b_sizeOfValue == false)
{
    //printf("Bitte die erste Primzal eingeben:\n");
    //scanf("%d",&p);
    //fflush(stdin);

    while(bool_temp == 0)
    {
        p = CreateRandomNumber();

        if(isPrimeN(p) == true)
        {
            bool_temp = 1;
        }
    }

    bool_temp = 0;

    while(bool_temp == 0)
    {
        q = CreateRandomNumber();
        if(isPrimeN(q) == true && p!=q)
        {
            bool_temp = 1;
        }
    }

    if((p*q)>200 && p!=q)
        b_sizeOfValue = true;
}
    printf("Zuerst werden 2 Primzahlen benötigt, diese wurden für Sie generiert! Es sind\np = %d\nund\nq = %d\n\n(Weiter mit der Entertaste)");
    while(c!="\n")
    {
        scanf("%s",c);
    }

    n = (p*q);
    e = CalculateEncodingExponent(p,q);
    d = CalculateDecipheringExponent(p,q,e);

    verschluesseln(M,n,e,d);
}

bool isPrimeN(int zahl)
{
    bool temp = true;
    for (int i = 2;i <= zahl-1;i++)
    {
        if(zahl%i == 0)
        {
            temp = false;
        }
    }

    return temp;
}

int ggt(int a, int b)
{
    if(a<0)
    {
        a *=-1;
    }
    if(b<0)
    {
        b *=-1;
    }
    while(a!=b)
    {
        if(a<b)
        {
            b=b-a;
        }
        else if(b<a)
        {
            a=a-b;
        }
    }
    return a;
}

int teilerfremd(int a, int b)
{
    int x=ggt(a,b);

    if(x!=1)
        return 0;
    else
        return 1;
}
int CreateRandomNumber()
{
    int zahl;
    srand(time(NULL));
    zahl = rand();
    return zahl;
}
int CalculateEncodingExponent(int p, int q)
{
    int zahl = 1;
    int temp = 0;
    int x = (p-1)*(q-1);

    printf("erstelle zufaellige Primzahl...\n");

    while(temp == 0)
    {
        zahl = CreateRandomNumber();
        if(isPrimeN(zahl) == true && teilerfremd(zahl,x)==1)
        {
            temp = 1;
        }
    }

    printf("Zufaellige Primzahl = %d\n",zahl);
    return zahl;
}

int CalculateDecipheringExponent(int p, int q, int zweiteZ)
{
    int zahl,mod,erg;

    printf("berechne 3. Zahl...\n");

    mod = (p-1)*(q-1);

    for(int i = 1;i>0;i++)
    {

        erg = (zweiteZ*i)%mod;
        if(erg == 1)
        {
            zahl = i;
            i = -1;
        }
    }
    printf("errechnete 3.Zahl = %d\n",zahl);
    return zahl;
}

void verschluesseln(char nachricht[5],int n, int e,int d)
{
    int zahl;
    int message[5];
    int hilf;
    char temp;
    printf("\nIhre Nachricht in verschluesselter Form: ");
    for(int i = 0;i<=5-1;i++)
    {
        zahl = (int)nachricht[i];
        if(zahl!=0)
        {
            hilf = zahl;
            for(int k = 0;k<=e-2;k++)
            {
                zahl *=hilf;
                zahl = zahl%n;
            }
            message[i] = zahl;
            printf("%d",zahl);
        }
    }
    printf("\nDecodieren...\nDecodierte Nachricht: ");
        for(int j = 0;j<=5-1;j++)
        {
            zahl = message[j];
            hilf = zahl;
            for(int f = 0;f<=d-2;f++)
            {
                zahl *=hilf;
                zahl = zahl%n;
            }
            temp = (char)zahl;
            printf("%c",temp);
        }
}

_________________
Programmieren ist ein Rennen zwischen den Softwareentwicklern, die versuchen größere und bessere idiotensichere Programme zu schreiben und dem Universum, welches versucht größere und bessere Idioten zu produzieren. Zur Zeit liegt das Universum in Führung.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 03.03.11 11:05 
Bin kein C-Spezi, aber vielleicht liegt der Fehler gar nicht in der Deklaration. Die scheint meiner Ansicht nach korrekt zu sein.

Probiere mal folgende Änderung:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
bool isPrime(int Number)
{
    for(int i = 2;i<=Number-1;i++)
    {
        //if(Number%i == 0)
        if((Number%i) == 0)
        {
            return false;
        }
    }
    return true;
}
traceurmicha Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 160
Erhaltene Danke: 9

Win XP SP2, Win 7 Pro., Ubuntu 9, Debian 5
C#, ASP.NET, MSSQL, PHP(Microsoft Visual Studio 2010 Ultimate, SharpDevelop 4, Microsoft SQL Server2008 Express, Eclipse for PHP)
BeitragVerfasst: Do 03.03.11 12:07 
Bringt auch nix

_________________
Programmieren ist ein Rennen zwischen den Softwareentwicklern, die versuchen größere und bessere idiotensichere Programme zu schreiben und dem Universum, welches versucht größere und bessere Idioten zu produzieren. Zur Zeit liegt das Universum in Führung.