revert between 56095 -> 55830 in arch
[AROS.git] / compiler / alib / acrypt.c
blobe23d7ceca1d9cc3627315d2353e19a9e0921f00c
1 /*
2 * $Id$
4 * :ts=4
6 * Portable ISO 'C' (1994) runtime library for the Amiga computer
7 * Copyright (c) 2002-2006 by Olaf Barthel <olsen (at) sourcery.han.de>
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * - Neither the name of Olaf Barthel nor the names of contributors
18 * may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 #define ACrypt __ACrypt
36 #include <exec/types.h>
37 #include <clib/alib_protos.h>
39 #undef ACrypt
41 /****************************************************************************/
43 #include <aros/debug.h>
45 /****************************************************************************/
47 #define OSIZE 12
49 /****************************************************************************/
51 UBYTE * ACrypt(UBYTE * buffer, const UBYTE * password, const UBYTE * user);
53 /****************************************************************************/
55 UBYTE *
56 ACrypt(UBYTE * buffer, const UBYTE * password, const UBYTE * user)
58 UBYTE * result = NULL;
59 LONG buf[OSIZE];
60 LONG i,d,k;
62 //ENTER();
63 //ALIVE
65 //assert( buffer != NULL && password != NULL && user != NULL );
67 //SHOWPOINTER(buffer);
68 //SHOWSTRING(password);
69 //SHOWSTRING(user);
70 D(bug("[ACrypt] buffer %p password %s user %s\n", buffer, password, user));
72 if(buffer == NULL || password == NULL || user == NULL)
74 //SHOWMSG("invalid parameters");
75 D(bug("[ACrypt] invalid parameters\n"));
76 goto out;
79 for(i = 0 ; i < OSIZE ; i++)
81 if((*password) != '\0')
82 d = (*password++);
83 else
84 d = i;
86 if((*user) != '\0')
87 d += (*user++);
88 else
89 d += i;
91 buf[i] = 'A' + d;
94 for(i = 0 ; i < OSIZE ; i++)
96 for(k = 0 ; k < OSIZE ; k++)
97 buf[i] = (buf[i] + buf[OSIZE - k - 1]) % 53;
99 buffer[i] = buf[i] + 'A';
102 buffer[OSIZE-1] = '\0';
104 //SHOWSTRING(buffer);
105 D(bug("[ACrypt] buffer %s\n", buffer));
107 result = buffer;
109 out:
111 //RETURN(result);
112 D(bug("[ACrypt] return value %s\n", result));
113 return(result);